我有一个扩展ArrayAdapter<String>
的类来显示不同行的不同图像,我不确定这是否正确。现在我的问题是:如何显示ArrayList中的项目,图像显示正常,但我无法设置文本。我在一个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;
}
}
答案 0 :(得分:2)
String text = list_text.get(position);
holder.textView.setText(text);