Android - Activity vs. ListActivity - Which one should my activity class extend?

后端 未结 3 507
半阙折子戏
半阙折子戏 2020-12-14 00:52

I\'ve been learning to develop in Android and had more of a general question: If I have a layout that uses a list and some other views, should I be using Activity or ListAct

相关标签:
3条回答
  • 2020-12-14 01:35

    I'd use a ListActivity since it gives you a lot of shortcut methods to make things easier and keep your code more readable.

    For example, you get the onListItemClick() method which is called whenever you click a item which saves you from creating a separate listener.

    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 and see that it doesn't do all that much other than make your life a little easier.

    0 讨论(0)
  • 2020-12-14 01:37

    I'd go with Activity. Don't really see the reason to use ListActivity, unless you want to do something trivial and you know it's gonna be with the List.

    0 讨论(0)
  • 2020-12-14 01:42

    You should use Activity rather than ListActivity because ListActivity codes are non-reusable and you need to write them again and again.

    0 讨论(0)
提交回复
热议问题