Kevik
Kevik

Reputation: 9351

Advantage of ListFragment over a ListView or normal Fragment

I have an activity with a menu of items running down the left side that are textViews. when the user selects one of the textViews it will put a listView in the rest of the area of the activity taking up the other 2\3 of the screen. when the user touches a different textView on that left side menu of the page, it will open a different corresponding listView of items.

i was considering putting a large listview on the screen for this purpose. however one other way is instead of using a regular listView in the activity, i could put a list fragment in there and switch between fragments.

The third choice is to put a fragment in there and put a listView inside of that fragment. I have never used ListFragment before.

which would be the best plan considering that there will be no orientation change? the activity will be locked in the vertical / portrait orientation. this will be running on a tablet, not used on smaller devices like phones.

i don't know if i will need to use loaders, because the list will not be long and the contents of the list will be text only.

is there any advantage to using listFragment over the other choices?

The three choices for this activity:

  1. activity with ListView on it

  2. activity with ListFragment on it

  3. activity with fragment on it that has ListView inside of theFragment`

Upvotes: 26

Views: 11132

Answers (1)

user
user

Reputation: 87064

A ListFragment is basically a slightly specialized Fragment which makes handling a ListView present in the layout of the Fragment easier by offering some convenience methods(like getListView() so you don't need to search for the widget yourself, a method to get the adapter of the ListView etc). If you need a Fragment with a ListView, use a ListFragment. So in the end it's about deciding between a ListView and a ListFragment.

Between the two options, taking in consideration your scenario, I would simply use a ListViewbecause it's plain simple. The need of a Loader isn't a problem as you could use the LoaderManager of the Activity for the ListView.

However, you didn't mention how the BACK button should be handled. If you want to offer the user the possibility of navigating back through his choices use a Listfragment to get that for free from the system.

Upvotes: 13

Related Questions