ListActivity
is to simplify the handling of ListView
. It extends Activity
and provides simplified handling of lists.
Difference with Activity
- Override
onListItemClick()
method to add item click listener. With Activity
, we need to create a separate listener with OnClickListener
.
- No need to use
findViewById()
to find listview in layout resource.
- Could show a special view to replace list view automatically when there is no data in list.
setListAdapter()
to set adapter instead of calling ListView.setAdaper()
.
Please inform me if any expert know more about it.
Example
Points to pay attention:
ListView
must set id @android:id/list
. So ListActivity
could find it automatically.
- The view to show when there is no data in the list must set id
android:id/empty
.
Then extend ListActivity
and override onListItemClick()
to add item listener
Refs