Use ListView or RecyclerView in NavigationDrawer?

I am a little confused about whether to use RecyclerView or ListView in DrawerLayout.
I read a tutorial that explains how to create a navigator using a RecyclerView.
According to google: RecyclerView is 1) a container for displaying large datasets that can be scrolled very efficiently while maintaining a limited number of views.
2) Uses an internal layout manager. The layout manager positions the item views within the RecyclerView and determines when to reuse views of items that are no longer visible to the user. To reuse (or recycle) a view, the layout manager can ask the adapter to replace the view's content with another item from the dataset.

Since there is a very small dataset in the navbox (title + shortlist) and all items are still visible to the user, I would not be able to take advantage of the "features" of the recyclers in 1) and 2).
Even Google used ListView in NavigationDrawer .
I guess I could use ListView.addHeader()

to create a custom view for the title in the DrawerLayout.
So my question is, if I prefer RecyclerView over ListView in DrawerLayout?

+3


source to share


3 answers


Using the navigation box is very difficult, Google has come up with a better and simpler way to implement the NavigationView boxes and your list should now be a "menu" that you can define in a separate XML file, no need for adapters anymore. For more information on how to implement it, check the official android blog here



+2


source


The same question was bogging my mind when I was developing a material design navigation box for my application.

Even you can see an overview of the RecyclerView class that defines

Flexible view to provide a limited window for a large dataset.



And our navigation drawer has a fixed number of items.

So, perhaps you set the parameter public void setHasFixedSize (boolean hasFixedSize)

to true. This will make it almost a ListView.

I am using ListView in my box and you should be using ListView as well.

+1


source


Your explanation is good. Now, answering your question, if you plan on using expandable list items in your nav drawer in the future, you need to be prepared to implement an expandable recyclerview (which doesn't exist by default) if you are using it RecyclerView

now. So in this case ExpandableListView

it would be a simpler solution to implement. However, if you don't need any extensible element elements inside your box, it would be better to use RecyclerView

if you are using a large dataset. As you said you have a small dataset, I don't think it will make a big difference if you use ListView

or RecyclerView

. However, as RecyclerView

is more flexible, why not use only RecyclerView

.

As per your requirements, I would recommend importing the Android design support library for you to use NavigationView

, which makes it easier by providing the frames needed for the nav drawer as well as the ability to inflate nav elements through the menu resource.

0


source







All Articles