0

我仍然不清楚在不需要基本 SimpleAdapter 的情况下使用哪个适配器。有 BaseAdapters、ArrayAdapters、CustomAdapters 等。

我想用一个简单的布局制作一个 ListView,就像在 Google PlayStore 的评论部分看到的那样。一侧的 TextView 和弹出某种上下文菜单的图像。

我会为此使用哪种适配器效果最好?

4

1 回答 1

0

在您的情况下,使用SimpleAdapter. 只需提供您的自定义布局并将数据与小部件的 id 连接起来。与此类似的东西:

List<HashMap<String,String>> datalist = new ArrayList<HashMap<String,String>>();

HashMap<String, String> map = new HashMap<String,String>();
map.put("text", "some text");
map.put("image",Integer.toString( R.drawable.your_image_to_popup_a_menu ));
datalist.add( map );

String[] from = { "text","image" };
int[] to = { R.id.txt,R.id.img };

SimpleAdapter adapter = new SimpleAdapter( this, datalist, R.layout.your_layout, from, to);

不要忘记将布局的 TextView 和 ImageView 分别标识为"@+id/txt""@+id/img"

(如果您的图像始终相同,只需在布局中设置它并忘记链接R.id.img部分)

于 2012-06-26T18:34:00.277 回答