各行に画像とテキストを表示したい場合、および同じために 2 つの arraylist を使用している場合、ここに解決策があります。これを試して
List<Integer> imageList = getImageList(); //list of drawable ids
List<String> values = getValues();
class CustomAdapter extends BaseAdapter {
@Override
public int getCount() {
// TODO Auto-generated method stub
return imageList.size();;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// inflate the layout which contains imageview and textview which are aligned horizontally.
//Assuming you inflated layout and got imageView and textview from that layout
textView.setText(values.get(position));
imageView.setImageResource(imageList.get(position));
return convertView;
}
}
//コードを直接コピーして貼り付けると機能しません。ロジックを使用し、それに応じて変更します
2 つの arraylist を使用する代わりに、HashMap を使用することをお勧めします。キーとしてイメージパス、値としてテキスト。