【发布时间】:2014-09-12 07:09:54
【问题描述】:
我正在尝试使用SimpleAdapter 在我的ListView 中inflate 两个不同的Layouts。我已经完成了以下编码,两个布局都在膨胀,但是 ArrayList<HashMap<String,String>> 的内容没有设置到 ListView 中。谁能一步一步指导我哪里出错了?
ListAdapter k = new SimpleAdapter(Table_Order_Activity.this,
cart_activity.table_order_items, R.layout.menulist,
new String[] { "Food_Name", "Pref_Name", "Food_Currency",
"Food_Price", "Food_Price_Total", "Pref_ID",
"Food_Image" }, new int[] { R.id.cat_name,
R.id.textView1, R.id.textView2, R.id.textView3,
R.id.url, R.id.veggie, R.id.Category }) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = super.getView(position, convertView, parent);
LayoutInflater inflater = (LayoutInflater) getApplicationContext()
.getSystemService(
Table_Order_Activity.this.LAYOUT_INFLATER_SERVICE);
int type = getItemViewType(position);
Log.i("position + convertview + type ", "" + position + ","
+ convertView + "," + type);
TextView image_url = (TextView) v.findViewById(R.id.Category);
ImageView image = (ImageView) v.findViewById(R.id.imageView1);
imageloader.DisplayImage(image_url.getText().toString(), image);
if (type == 0) {
v = inflater.inflate(R.layout.r2, parent, false);
} else if (type == 1) {
v = inflater.inflate(R.layout.menulist, parent, false);
}
return v;
}
@Override
public int getItemViewType(int position) {
int type = 0;
Log.i("position in getitemviewtype", "" + position);
if (position == 0) {
type = FIRST_TYPE;
} else if (position == 1) {
type = SECOND_TYPE;
}
/*
* else if (position == 2) { type = FIRST_TYPE; } else if
* (position == 3) { type = SECOND_TYPE; }
*/
return type;
}
};
table_order_list.setAdapter(k);
【问题讨论】:
-
为什么不扩展 BaseAdapter 或 ArrayAdapter?
标签: android listview layout-inflater simpleadapter