嗨,我在列表视图中使用列表视图,我有蔬菜和非蔬菜。所以当我点击蔬菜时,它应该移动到下一个活动并显示项目,当我点击非蔬菜时,它应该到下一个活动。我有为两个列表项编写了 setonclickitemlistener() 但是当我按下 veg 或 non-veg 时,它只会进入 Non-veg 活动。这是代码
public class MainActivity extends Activity {
String[] items={"veg","non-veg"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv= (ListView)findViewById(R.id.listView1);
ArrayAdapter<Object> adapter1 = new ArrayAdapter<Object (this,android.R.layout.simple_list_item_1,items);
lv.setAdapter(adapter1);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int arg2,
long arg3) {
{
Toast.makeText(getBaseContext(),"YOU HAVE SELECTED VEG", 4000).show();
Intent i=new Intent(MainActivity.this,veg.class);
startActivity(i);
}
}
});
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(getBaseContext(),"YOU HAVE SELECTED NON-VEG", 4000).show();
Intent i=new Intent(MainActivity.this,Nonveg.class);
startActivity(i);
}
});
} }
请告诉我如何识别蔬菜和非蔬菜的 id 以及如何编写 setonclicklistener() 方法。