Could someone tell me which one should I use? I mean in terms of "best practice". Thank you.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With