What are the differences between extending Activity and extending ListActivity?

前端 未结 4 1743
眼角桃花
眼角桃花 2021-02-14 03:47

I am using a class which extends Activity to obtain a list from an API...

In some apps which do basically the same, the devs extended ListActivity...

Which are t

4条回答
  •  爱一瞬间的悲伤
    2021-02-14 04:18

    ListActivities are specially designed to be used with ListViews. It provides several helper methods like onListItemClick(), which make it easier to use a ListView in them.

    You can do anything you can do in an Activity in a ListActivity.

    If you want to change the layout of a ListActivity you still can with setContentView() method from Activity. As long as there is a ListView called @android:id/list somewhere in your View the ListActivity will still work.

    If you're still not sure, you could always look at the source code for ListActivity (Jelly Bean code linked to) and see that it doesn't do all that much other than make your life a little easier.

提交回复
热议问题