I want to display the arrayList items in ListView which is having 2 different textViews. I am using ListViewCustomAdapter and getView(),getItem()... methods are there.
This is my code: MyCustom.java:
public class MyCustom extends BaseAdapter {
public Activity context;
public LayoutInflater inflater;
ArrayList mylist;
public MyCustom(Activity context,ArrayList viewList) {
super();
this.context=context;
this.mylist=viewList;
inflater=(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mylist.size();
}
@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;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View List;
if(convertView==null)
{
List=new View(context);
LayoutInflater mLayoutinflater=(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
List=mLayoutinflater.inflate(R.layout.listitem_row, parent, false);
}
else
{
List=(View)convertView;
}
TextView t1=(TextView)List.findViewById(R.id.txtViewTitle);
t1.setText((CharSequence) mylist.get(position));
TextView t2=(TextView)List.findViewById(R.id.txtViewDescription);
t2.setText(mylist.get(position).toString());
return List;
}
}
Above code, there is problem as mentioned below. This will be display the arrayList items as same in both the textviews in ListView. Ex: mylist=['a1','a2','b1','b2'] this is my arraylist and passing to MyCustomAdapter.
At runtime, 'a1' will be displayed in both the textviews.and so on.
I want to display 'a1' in textView1 and 'a2' is in textView2.. and b1 is .. so on...
I think i may have problem in getItem(), getItemId(), getcount() method.. PLEASE HELP ME...