可以为listview设置自定义的Adapter,该自定义Adapter继承BaseAdapter
class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
// TODO Auto-generated method stub
return list!=null?list.size():0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = getLayoutInflater().inflate(R.layout.data_list, null);
TextView name = (TextView) v.findViewById(R.id.name);
name.setText((String) list.get(position).get("name"));
return v;
}
}
其中getView方法可以通过getLayoutInflater().inflate()方法为每个条目设置不同的布局。