AdapterView.OnItemClickListener itemClickListener=new
AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> listView, int position, View v, long id) {
if (position == 0) {
Intent intent=new Integer(TopLevelActivity.this, DrinkCategoryActivity.class);
startActivity(intent);
}
}
};
答案 0 :(得分:1)
我们假设您的AdapterView
为ListView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
Intent intent = new Intent(TopLevelActivity.this, DrinkCategoryActivity.class);
startActivity(intent);
答案 1 :(得分:0)
您需要将听众设置为ListView
。这就是它无法正常工作的原因。
这样做:
AdapterView.OnItemClickListener itemClickListener =
new AdapterView.OnItemClickListener() { ... }; // create listener (you did that already)
listView.setOnItemClickListener(itemClickListener); // set listener