因此,我在列表视图中使用了自定义视图,并且试图获得被单击视图的位置,但是我什至无法使调试器显示任何内容。我不知道这有什么问题,我们将不胜感激。
ListAdapter BryceAdapter=new CustomAdapter(this,Restaurants,imgs);
ListView BryceListView=(ListView)findViewById(R.id.BryceListView);
BryceListView.setAdapter(BryceAdapter);
BryceListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.e(TAG, "onItemClick: ");
}
}
);
最佳答案
您只需要添加+ position
,如下所示:
ListAdapter BryceAdapter=new CustomAdapter(this,Restaurants,imgs);
ListView BryceListView=(ListView)findViewById(R.id.BryceListView);
BryceListView.setAdapter(BryceAdapter);
BryceListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.e(TAG, "onItemClick: " + postion);
}
}
);