gpt4 book ai didi

Android:自定义ArrayAdapter中的多个数组

转载 作者:行者123 更新时间:2023-11-29 02:10:30 25 4
gpt4 key购买 nike

我想为我的自定义 ArrayAdapter 传递多个数组。这是我的阵列和我想要做的:

String[] names = new String[]{ "One", "two", "three" };

String[] texts = new String[]{ "Bacon", "Eggs", "Cheese" };

Customadapter ap = new Customadapter(this, names, texts);
setListAdapter(ap);

这是我的自定义 ArrayAdapter:

public class Customadapter extends ArrayAdapter<String> {

private final Activity context;
private final String[] names;

public Customadapter(Activity context, String[] names) {
super(context, R.layout.row, names);
this.context = context;
this.names = names;
}

@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.row, null, true);
TextView tw1 = (TextView) rowView.findViewById(R.id.label);
TextView tw2 = (TextView) rowView.findViewById(R.id.label2);

String text = names[position];
tw2.setText(text);

return rowView;

}

}

最佳答案

而不是 ArrayAdapter<Strings>您需要创建 ArrayAdapter<HashMap<String,String>> 的适配器

关于Android:自定义ArrayAdapter中的多个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7730203/

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