我想在ListView中顯示具有2個不同textView的arrayList項目。 我正在使用ListViewCustomAdapter和getView(),getItem()...方法在那裏。在ListView中顯示ArrayList項目包含2個文字瀏覽
這是我的代碼: 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;
}
}
上面的代碼,如下所述存在問題。 這將在ListView中的文本視圖中顯示arrayList項目。這是我的數組列表,並傳遞給MyCustomAdapter。
在運行時,'a1'將顯示在textviews.and等。
我想顯示textView1 'A1' 和 'A2' 是textView2 ..和B1是..等等...
我想我可以在getItem()時,getItemId有問題() ,getCount將()方法.. 請幫我...
不工作...我想顯示'a1'到textview1和以下'a2'到textview2 ... – EESHA 2012-03-09 09:47:27
已更新。所以考慮列表中的對象結構。爲了更好地理解,列表中的每個對象都代表一行。因此,列表中的每個對象應包含有關該行的所有數據。 – Hanon 2012-03-09 09:57:00