Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListFragment vs ListActivity - Which one to use?

Could someone tell me which one should I use? I mean in terms of "best practice". Thank you.

like image 303
Azat Avatar asked Feb 08 '12 10:02

Azat


People also ask

What is ListFragment?

A fragment that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. The basic implementation of list fragment is for creating list of items in fragments.

What is ListActivity?

This class was deprecated in API level 30. ListActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results. Binding, screen layout, and row layout are discussed in the following sections.

How do you use ListFragment?

Create a class MyListFragment and extend it to ListFragment. Inside the onCreateView() method , inflate the view with above defined list_fragment xml layout. Inside the onActivityCreated() method , create a arrayadapter from resource ie using String array R. array.


1 Answers

If you have tablet design in mind, you should probably use listfragment instead of listactivity. You can still easily wrap fragment in a activity for phone design. Developing app using fragment is a good design pattern. you can read more in here. http://android-developers.blogspot.com/2011/09/preparing-for-handsets.html

like image 188
CChi Avatar answered Oct 23 '22 19:10

CChi