android - problem with customlist view? -


below code customlist.

package com.demo.list;  import java.util.arraylist;    import android.app.listactivity; import android.app.progressdialog; import android.content.context; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.baseadapter; import android.widget.imageview; import android.widget.textview;  public class mycustomlistview extends listactivity {     private arraylist<string> m_orders=null;     private orderadapter m_adapter;     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         m_orders = new arraylist<string>();         for(int i=0;i<10;i++)         {             m_orders.add("android list");         }         this.m_adapter = new orderadapter(this, r.layout.row, m_orders);                 setlistadapter(this.m_adapter);     }     private class orderadapter extends baseadapter     {         private arraylist<string> items;         public orderadapter(context context,int id,arraylist<string> items)         {             super();             this.items=items;         }          public view getview(int position,view convertview,viewgroup parent)         {             view view=convertview;             if(view==null)             {                 layoutinflater inflater=(layoutinflater)getsystemservice(context.layout_inflater_service);                 view=inflater.inflate(r.layout.row,null);             }             string string=items.get(position);             if(string!=null)             {                 textview t1=(textview)findviewbyid(r.id.toptext);                 textview t2=(textview)findviewbyid(r.id.bottomtext);                 imageview imageview=(imageview)findviewbyid(r.id.image);                 if(t1!=null)                 {                     t1.settext("name:-"+string.tostring());                 }                 if(t2!=null)                 {                     t2.settext("status:-"+string.tostring());                 }             if(imageview!=null)                 {                     imageview.setimageresource(r.drawable.icon);                 }             }             return view;         }          @override         public int getcount() {             // todo auto-generated method stub             return 10;         }          @override         public object getitem(int position) {             // todo auto-generated method stub             return position;         }          @override         public long getitemid(int position) {             // todo auto-generated method stub             return position;         }     } } 

and here row.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent" android:layout_height="?android:attr/listpreferreditemheight">     <imageview android:id="@+id/image" android:layout_width="wrap_content"         android:layout_height="fill_parent" android:layout_marginright="6dip">     </imageview>     <linearlayout android:orientation="vertical"         android:layout_width="0dip" android:layout_height="fill_parent"         android:layout_weight="1">         <textview android:id="@+id/toptext"                   android:layout_width="fill_parent"                   android:layout_height="0dip"                   android:layout_weight="1"                   android:gravity="center_vertical"/>         <textview android:id="@+id/bottomtext"                   android:layout_width="fill_parent"                   android:layout_height="0dip"                   android:layout_weight="1"                   android:singleline="true"                   android:ellipsize="marquee"/>         </linearlayout> </linearlayout 

my problem getting first element of list though have added 10 elements arraylist. can tell me wrong code.

you should replace:

view=inflater.inflate(r.layout.row,null); 

with:

view=inflater.inflate(r.layout.row, parent, false); 

edit:

also, replace:

textview t1=(textview)findviewbyid(r.id.toptext); textview t2=(textview)findviewbyid(r.id.bottomtext); imageview imageview=(imageview)findviewbyid(r.id.image); 

with:

textview t1=(textview)view.findviewbyid(r.id.toptext); textview t2=(textview)view.findviewbyid(r.id.bottomtext); imageview imageview=(imageview)view.findviewbyid(r.id.image); 

btw: of adapter coded incorrectly. i'm assuming because you're trying see working.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -