Для ListActivity проще всего переопределить onListItemClick
в самом действии.
РЕДАКТИРОВАТЬ:
Вот что я имею в виду:
public class test extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] choose = getResources().getStringArray(R.array.list_chooser);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, choose));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// Start another activity to do something with the selected item.
// I'll assume the other activity is defined in the class
// AnotherActivity:
Intent intent = new Intent(this, AnotherActivity.class);
// now you can add additional information to the intent for the
// other activity to use. For instance, to pass just the index of the
// selected item, you could code:
intent.putExtra("KEY_SELECTED_INDEX", position);
// (The string "KEY_SELECTED_INDEX" is an arbitrary string you choose
// to name this piece of data. AnotherActivity will use the same name
// to retrieve it. Other extras would be added under different names.)
startActivity(intent);
}
}
Тогда вам потребуется определить отдельное действие для отображения второго вида:
public class AnotherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
int position = intent.getIntExtra("KEY_SELECTED_INDEX", -1);
if (position == -1) {
Toast.makeText(this, "No selection to show!", Toast.DURATION_LONG)
.show();
}
// continue with setting up the activity
}
}
Вам также необходимо добавить это второе действие в файл манифеста вашего приложения.