gpt4 book ai didi

java - 从 Item Press 上的 SimpleAdapter/ListView 检索原始 HashMap

转载 作者:行者123 更新时间:2023-11-30 09:46:14 24 4
gpt4 key购买 nike

我有一个填充 ListView 的 SimpleAdapter,但是当用户按下一个项目时,我希望能够获得用于填充被单击的行的原始 HashMap。不幸的是,似乎我能得到的只是一个只支持 toString() 的对象。从用户单击的 View 中获取字符串没有用,因为它不是唯一标识符。

如何取回用户点击行的数据?

ArrayList<HashMap<String, String>> reformedBundle = new ArrayList<HashMap<String, String>>();
// [...]
mResultsAdapter = new SimpleAdapter(this,
reformedBundle, R.layout.resultrow,
new String[] { "ProviderName", "Street", "City" },
new int[] { R.id.tvField1, R.id.tvField2, R.id.tvField3
});

lvResults.setAdapter(mResultsAdapter);

lvResults.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
// Here's where I want to get the original HashMap<String, String> so I can query other keys in the HashMap
}
});

最佳答案

我存储在一个成员变量中。

private ArrayList<HashMap<String, String>> reformedBundle;

...

lvResults.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
HashMap<String, String> map = reformedBundle.get(pos);
}
});

关于java - 从 Item Press 上的 SimpleAdapter/ListView 检索原始 HashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7237519/

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