我使用了一些项目进行了ListView,现在我想点击特定项目时发送给我' next'活性。
我写这段代码:
listViewProduct.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> list, View v, int pos, long id) {
Intent intent = new Intent(DrugaStranica.this, MainActivity.class);
startActivity(intent);
}
});
但它适用于所有项目,我希望特定项目将我发送给特定活动。
答案 0 :(得分:1)
请使用以下代码,它可能有助于解决您的问题。
listViewProduct.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> list, View v, int pos, long id) {
Intent intent;
switch (pos) {
case 0:
intent = new Intent(DrugaStranica.this, TestOneActivity.class);
break;
case 1:
intent = new Intent(DrugaStranica.this, TestTwoActivity.class);
break;
case 2:
intent = new Intent(DrugaStranica.this, TestThreeActivity.class);
break;
case 3:
intent = new Intent(DrugaStranica.this, TestFourActivity.class);
break;
default:
intent = new Intent(DrugaStranica.this, MainActivity.class);
break;
}
startActivity(intent);
}
});