I want to open an activity depends on the value user select on a ListView. If user select a list item that have type1 value it should open acitvity1 (activity1.class), if the list item belongs to type2 it should open acitvity2 (activity2.class). I still wants to get the id value.
Can some one please help me to get more than one values in a list. (not just the id value) or a work around for this.
following is my code;
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
//TODO:need to assign the value here
String mEdit = .......;
if (mEdit.equals("type1")){
Intent i = new Intent(this, activity1.class);
i.putExtra(DbAdapter.KEY_ROWID, id );
startActivityForResult(i, ACTIVITY_EDIT);
}else if (mEdit.equals("type2")){
Intent i = new Intent(this, activity2.class);
i.putExtra(KEY_ROWIDA, id );
startActivityForResult(i, ACTIVITY_EDIT);
};
}
Thanks in advance
You can call getListView().getItemAtPosition(int) on your ListActivity and give it the index of the list item. You can then cast it to whatever the backing object is and perform any operations on that Object. Example from one of my own apps:
ForumDescriptor has some information about an individual subforum (it’s a forums viewer for a website). Each one is an item in my list.