ArrayAdapter<String>
行ごとに異なる画像を表示するように拡張するクラスがありますが、これが正しい方法かどうかはわかりません。今私の問題は次のとおりです。ArrayList からアイテムを表示するにはどうすればよいですか。画像は正常に表示されますが、テキストを設定できません。そして、アイコンとテキストを 1 つの TextView に表示します。
class MyAdapter extends ArrayAdapter<String> {
Context context;
int layoutResourceId;
ArrayList<String> list_text;
public MyAdapter(Context context, int layoutResourceId, ArrayList<String> list_text) {
super(context, layoutResourceId, list_text);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.list_text = list_text;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
MyItemHolder holder = null;
if(row == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new MyItemHolder();
holder.iconView = (TextView)row.findViewById(R.id.item);
holder.textView = (TextView)row.findViewById(R.id.item);
row.setTag(holder);
}
else {
holder = (MyItemHolder)row.getTag();
}
int d = R.drawable.picture;
?ArrayList<String> text = list_text;
holder.iconView.setCompoundDrawablesWithIntrinsicBounds(d, 0, 0, 0);
?holder.textView.setText(text);
return row;
}
static class MyItemHolder {
TextView iconView;
TextView textView;
}
}