What are the differences between extending Activity and extending ListActivity?

前端 未结 4 1727
眼角桃花
眼角桃花 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:12

    ListActivity extends the functionality of the common android.app.Activity by providing a number of list centric features 'for-free' if you like. For example, the handling of a list entry click is neatly contained within ListActivity's onListItemClick(...) whereas if you were using a plain android.app.Activity then you would need to implement this manually with an OnClickListener and implementation.

    By all accounts, if your layout contains a list then use a ListActivity/ListFragment since it is a useful extension. It does not mean your whole screen layout has to be list but a portion of it has to host a ListView widget with identifier, id="@android:id/list".

    The Javadoc on the class with useful examples of how to use it can be found here.

提交回复
热议问题