0
我想创建一个ListView,其中包含一个包含ImageView和另一个布局(线性)的RelativeLayout。线性布局包含一些TextView。创建包含布局的ListView
如何创建此ListView?
感谢 迪帕克
我想创建一个ListView,其中包含一个包含ImageView和另一个布局(线性)的RelativeLayout。线性布局包含一些TextView。创建包含布局的ListView
如何创建此ListView?
感谢 迪帕克
您可以为各行的布局。我们假设ImageView是R.id.image
和TextView R.id.text
。行布局是R.id.row_layout
对于列表,您需要一个列表适配器。如果使用ListActivity
它可能是这样的:
@Override
protected void onCreate(Bundle savedInstanceState){
...
ArrayList<HashMap<String, Object>> listData = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> m = new HashMap<String, Object>();
m.put("image", R.drawable.some_image);
m.put("text", "Test");
listData.add(m);
adapter = new SimpleAdapter(this,
listData, R.layout.row_layout,
new String[] {"image", "text"},
new int[] {R.id.image, R.id.text});
setListAdapter(adapter);
}
ArrayList中包含列表中的所有数据。每一行都用一个HashMap表示,数据的键必须等于你想要显示它们的ID。在适配器中,您说关键图像映射到ImageView等等。
你的意思是每一行都是你描述的RelativeLayout?如果是这样,那很简单。你有没有看过'ListAdapter'和'BaseAdapter'类? – 2010-08-11 07:29:52