我的活动中有两个ListViews
使用相同OnItemClickListener
的 . 有什么方法可以确定ListViews
我现在正在按下哪个元素?我用过这段代码:
@Override
public void onItemClick(AdapterView<?> list, View view, int position,
long id) {
if (view.getId() == R.id.listDictionary) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, WordActivity.class);
DictionaryListElement ele = (DictionaryListElement) dictionaryList
.getAdapter().getItem(position);
intent.putExtra("word", ele.getWord());
startActivity(intent);
} else if (view.getId() == R.id.listFavourites) {
Intent intent = new Intent(MainActivity.this, WordActivity.class);
String ele = (String)favouritesList.getAdapter().getItem(position);
intent.putExtra("word", ele);
startActivity(intent);
}
}
但它不起作用。我认为它正在获取每个按下元素的 id 而不是ListViews