I am working on an android app, and I am having difficulties with ListActivity. I would like to have a different Activity start depending on which item in the list is clicked.
I made a list and referenced it with setListAdapter in java, but I am not sure how to reference in the OnListItemClick. I assume I need to reference the position in the list.
With Activity and Buttons, I can set the OnClickListener and use a switch statement with a case for each Button. What is the equivalent for ListActivity?
Here is my code:
public class Options extends ListActivity implements {
String myHistory[]= { "Item 1", "Item 2", "Item 3" };
//---Set ListView---
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String> ( Options.this,
android.R.layout.simple_list_item_1, myHistory)));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
//--if click position 1, do below
//--Intent a = new Intent("show Item 1's corresponding page");
//--startActivity(a);
//--if click item in position 2, do below
//--Intent b = new Intent("show Item 2's corresponding page");
//--startActivity(b);
//--if click item in position 3, do below
//--Intent c = new Intent("show Item 3's corresponding page");
//--startActivity(c);
}
}
as looks there are only few and certain data in list not at run time because each item has a separate activity (like a menu list of game) so I will suggest to go short and simple …….