gpt4 book ai didi

android - 使用 arrayadapter> 填充 Listview

转载 作者:行者123 更新时间:2023-11-29 00:34:07 24 4
gpt4 key购买 nike

我正在使用以下代码,但它不会填充 ListView 。

  ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
lv.setAdapter(new ArrayAdapter<HashMap<String, String>> (this,android.R.layout.simple_list_item_1 , menuItems));

问题是上面的代码成功创建了适配器,但它没有显示在 ListView 中。

谢谢

最佳答案

您可以实现 SimpleAdapter 来填充 HashMap 的 ArrayList 中的数据:

SimpleAdapter listadapter = new SimpleAdapter(this, menuItems, R.layout.row,

new String[] {"textone", "texttwo", "txtthree"}, new int[]

{R.id.textone, R.id.texttwo, R.id.texttwo});

但为了实现SimpleAdapter您必须为单行中包含所需 View 的行创建布局

如需更多帮助,您可以查看以下教程以使用 hashMap 的 ArrayList 填充 ListView:

http://shenhengbin.wordpress.com/2012/03/17/listview-simpleadapter/

http://shenhengbin.wordpress.com/2012/03/17/listview-simpleadapter/

关于android - 使用 arrayadapter<HashMap<String, String>> 填充 Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13660662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com