[英]How to get text onClick from Listview that is using SimpleAdapter
I'm trying to get key+value (All text of row) item text when user is clicking a row, but i cant figure out how to do it, heres the code: 当用户点击一行时,我正在尝试获取键+值(行的所有文本)项目文本,但我无法弄清楚如何操作,继承代码:
lv = (ListView) findViewById(R.id.list_view);
simpleAdapter = new SimpleAdapter(
this,
scriptList,
android.R.layout.simple_list_item_2,
new String[] {"value","key"},
new int[] { android.R.id.text1,android.R.id.text2 });
lv.setAdapter(simpleAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//######
// HOW DO I GET THE ITEM TEXT (BOTH PARAMS, KEY + VALUE)?
});
parent.getItemAtPostion
returns the item at position. parent.getItemAtPostion
返回位置的项目。 In your case scriptList
should be an ArrayList<HashMap<String, String>>
. 在你的情况下,
scriptList
应该是一个ArrayList<HashMap<String, String>>
。 The item at position is therefore an HashMap<String, String>
. 因此,位置上的项目是
HashMap<String, String>
。
HashMap<String, String> item = (HashMap<String, String>) parent.getItemAtPostion(position);
String value = item.get("value");
String key = item.get("key");
You can use position
argument in onItemClick
method to get the data from your dataset. 您可以在
onItemClick
方法中使用position
参数来从数据集中获取数据。
HashMap<String, String> clickedItem = (HashMap<String, String>) scriptList.get(position);
String value = clickedItem.get("value");
String key = clickedItem.get("key");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.