当我点击ListView
中的不同列表项时,我希望得到不同的值。例如;当code = 1时我想得到不同的值,当code = 2时我想获得不同的值。我怎么能这样做?
这是我的代码。
Element e = (Element) nl.item(i);
map.put(KEY_CODE, conParser.getValue(e, KEY_CODE));
map.put(KEY_NAME, conParser.getValue(e, KEY_NAME));
map.put(KEY_COVERS, conParser.getValue(e, KEY_COVERS));
map.put(KEY_TABLE, conParser.getValue(e, KEY_TABLE));
map.put(KEY_SALES, conParser.getValue(e, KEY_SALES));
items.add(map);
}
final ListAdapter adapter = new SimpleAdapter(this, items,
R.layout.list_item,
new String[] {KEY_CODE,KEY_NAME,KEY_COVERS,KEY_TABLE,KEY_SALES},
new int[] {R.id.kod, R.id.name,R.id.person,R.id.table,R.id.sale});
setListAdapter(adapter);
ListView list= getListView();
reportList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
startActivity(new Intent(NewActivity.this,SingleNewActivity.class));
}
});
答案 0 :(得分:0)
目前尚不清楚你想要什么,但我发现你想要获得点击的项目。 因此在onItemClick方法中,parent参数是当前列表。所以你需要做的是从列表中获取适配器,然后点击项目,你知道,因为你有位置。所以基本上你必须在onItemClick里面写这个:
parent.getAdapter()。的getItem(位置)
并且您选择了项目,因此根据项目实例,您将获得id值,例如。 最好