gpt4 book ai didi

android - arrayadapter setText

转载 作者:行者123 更新时间:2023-11-29 00:35:48 26 4
gpt4 key购买 nike

我有一个扩展 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;
}
}

最佳答案

String text = list_text.get(position);
holder.textView.setText(text);

关于android - arrayadapter setText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12769203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com