我有兩個ListViews
在我的活動中使用相同OnItemClickListener
。有什麼方法可以確定我現在按哪個ListViews
元素?我已使用此代碼:Android識別listView使用onItemClick監聽器
@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);
}
}
但它不工作。我認爲它得到每個按下的元素不是ListViews
什麼是錯在上面的代碼? – Raghunandan
嘗試使用列表視圖ID不是view.getId() – Abx