我想为自定义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;
}
}
答案 0 :(得分:1)
您需要创建ArrayAdapter<Strings>
ArrayAdapter<HashMap<String,String>>
答案 1 :(得分:0)
请尝试使用SimpleAdapter。
答案 2 :(得分:0)
为启动器扩展BaseAdapter而不是ArrayAdapter,然后调整构造函数,使其获取文本字符串,以便将其存储在适配器中。这应该是主要的伎俩。有些方法需要覆盖afaik,但它在文档中有。