In the application I am writing, I have a main class which extends the ListActivity - it contains a list of elements. I want these elements to link to a different page (an xml one, or perhaps a View object). However, I realised one cannot use the method setContentView(int)
on a ListActivity object.
What's to be done?
Thanks!
Looks like you are trying to launch a new activity.
You have to override the onListItemClick
method of ListActivity
.
Here is the code.
// ListView l points to list view whose item user clicked // View v points to the item in the list view on which the user clicked // int position is the position index of the item in the list // long id is the id assigned to the item. This id is assigned using the ListAdapter, CursorAdapter etc. @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // I am using getApplicationContext() as it is more safe then just passing `this` Intent i = new Intent(this.getApplicationContext(), ActivityToRun.class); this.startActivity(i); }
NOTE: You have to improve on this skeleton depending upon your needs.
Have you tried setting the XML page as a ListView
and give it the ID @android:id/list
?