我已经让自己的CustomArrayAdapter显示了巴西餐馆的列表。我已经使用GetView方法来创建自己的自定义视图。填充自定义数组适应器
private class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.list_item, parent,false);
String [] items= getResources().getStringArray(R.array.locations_array);
TextView tv= (TextView) row.findViewById(R.id.textView1);
ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
tv.setText(items[position]);
iv.setImageResource(R.drawable.brazil);
return row;
}
}
当前这个新的GetView类从资源xml文件拉入文本字符串并将其放入列表项中。
- 如果我想要在应用程序中生成额外数据的数组,我假设我不会在GetView类中生成数组,因为每次创建新行时都会重新创建该数组。
- 我在哪里放置代码来创建数组,以及如何将这些数据调用到上面的GetView代码中?
嗨,当我尝试这种解决方案 - 我得到一个消息,新的lData不能解析为类型! – 2012-01-02 02:32:30
是的,在包含MyDataClass的行中有一个错误lData = new lData(); - 只是编辑它 – CodeDownZero 2012-01-02 02:51:35