gpt4 book ai didi

android - 我如何从 android ListView 中获取值?

转载 作者:行者123 更新时间:2023-11-29 22:09:05 26 4
gpt4 key购买 nike

您好,这是我的代码,我想访问我在 map 列表中放置在列表项上的 KEY_ID 单击一个变量..请帮助我如何做到这一点。

ArrayList (HashMap)  (String, String) mapList = new ArrayList(HashMap(String, String)) ();
XMLParser parser = new XMLParser();
Document doc = parser.getDomElement(xml);
// getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_Route);

// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();

Element e = (Element) nl.item(i);

// adding each child node to HashMap key => value

map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_SchoolName, parser.getValue(e, KEY_SchoolName));
map.put(KEY_ChildrenName, parser.getValue(e, KEY_ChildrenName));
map.put(KEY_AlertTime, parser.getValue(e, KEY_AlertTime));
map.put(KEY_RouteName, parser.getValue(e, KEY_RouteName));
map.put(KEY_Notification, parser.getValue(e, KEY_Notification));
map.put(KEY_StopName, parser.getValue(e, KEY_StopName));
// adding HashList to ArrayList
mapList.add(map);
}

list = (ListView) findViewById(R.id.list);

// Getting adapter by passing xml data ArrayList
adapter = new LazyAdapter(this, mapList);
list.setAdapter(adapter);

// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
int idw = position;
long logss = id;

// There i want to access the KEY_ID..

} catch (Exception e) {
e.printStackTrace();
progressDialog.dismiss();
}

}
});
}

最佳答案

在您的onItemClick 方法中,您需要从特定位置mapList 对象中获取HashMap:

HashMap<String, String> map = mapList.get(position);

//and then read values out from 'map' object

关于android - 我如何从 android ListView 中获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10088281/

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