2 つの異なる textView を持つ ListView に arrayList アイテムを表示したいと考えています。ListViewCustomAdapter と getView(),getItem()... メソッドを使用しています。
これは私のコードです: 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 アイテムが同じように表示されます。例: mylist=['a1','a2','b1','b2'] これは私の配列リストで、MyCustomAdapter に渡します。
実行時に、'a1' が両方のテキストビューに表示されます。
「a1」をtextView1に表示し、「a2」をtextView2に表示したい..そしてb1は..など...
getItem()、getItemId()、getcount() メソッドに問題があると思います。助けてください...