Hi I am using list view in my list view i have veg and non-veg.so when i click on veg it should move to next activity and display the items and when i click on Non-veg it should to next activity.I have written setonclickitemlistener() for both list items but when i press veg or non-veg it is going to Non-veg activity only.Here is the code
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);
}
});
} }
please tell me how to identify id for veg and non veg and how to write setonclicklistener() method.