gpt4 book ai didi

java - simple_list_item_2 模式下的空 ListView

转载 作者:太空宇宙 更新时间:2023-11-04 15:09:22 24 4
gpt4 key购买 nike

ArrayList<HashMap<String, String>> MemberList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> item = new HashMap<String, String>();

item.put("asdf", "asdf");
MemberList.add(item);
item.put("ffff", "ffff");
MemberList.add(item);
SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, MemberList, android.R.layout.simple_list_item_2, new String[] { "Name", "Level" },
new int[] { android.R.id.text1, android.R.id.text2 });

list.setAdapter(simpleAdapter);

这是我的java代码。

但是……只有两个空白

ListView中没有文本

我该怎么办?

最佳答案

更改为

  SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, MemberList, android.R.layout.simple_list_item_2, new String[] { "asdf", "ffff" },
new int[] { android.R.id.text1, android.R.id.text2 });

你有

 item.put("asdf", "asdf");
item.put("ffff", "ffff");

所以你需要

 new String[] { "asdf", "ffff" }, 

查看构造函数

public SimpleAdapter (Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)

Added in API level 1
Constructor

Parameters
context The context where the View associated with this SimpleAdapter is running
data A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entries specified in "from"
resource Resource identifier of a view layout that defines the views for this list item. The layout file should include at least those named views defined in "to"
from A list of column names that will be added to the Map associated with each item.
to The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter.

关于java - simple_list_item_2 模式下的空 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21542621/

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