请帮助从OnItemClickListener
获取“KEY_ID”的值适配器代码:
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
活动代码:
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
map.put(MainActivity.KEY_ID,MainActivity.parser.getValue(e,MainActivity.KEY_ID));
songsList.add(map);
adapter = new LazyAdapter(getActivity(), songsList);
list.setAdapter(adapter);
st.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String sss = ???????????????????????????????????? value of KEY_ID
}
});
请帮助。 感谢您提供的任何帮助
答案 0 :(得分:1)
尝试将onItemClick更改为:
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String sss = songsList.get(position).get(MainActivity.KEY_ID);
}
答案 1 :(得分:1)
您可以使用适配器,它更可靠。因为它对应于UI当前显示的内容:
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String value = ((Map<String, String>)adapter.getItem(position)).get(MainActivity.KEY_ID);
// 'adapter' can be either the field variable of the one you instantiated above OR by accessing the parameter 'parent' like this: parent.getAdapter()
}