Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ListView or RecyclerView in NavigationDrawer?

I am a little confused about whether to use RecyclerView or ListView in DrawerLayout.
I read a tutorial, which explains how to create a NavigationDrawer with RecyclerView.
According to google: RecyclerView is
1) a container for displaying large data sets that can be scrolled very efficiently by maintaining a limited number of views.
2) Uses internally a layout manager. A layout manager positions item views inside a RecyclerView and determines when to reuse item views that are no longer visible to the user. To reuse (or recycle) a view, a layout manager may ask the adapter to replace the contents of the view with a different element from the dataset.

Because there is a very small dataset (header + a short list) in Navigation Drawer and all items are still visible to user, I couldn't benefit from recycler view "features" in 1) & 2).
Even Google used ListView in NavigationDrawer.
I guess I could use ListView.addHeader() to create a special view for header in DrawerLayout.
So my question is If I should prefer RecyclerView over ListView in DrawerLayout ?

like image 445
FilipR Avatar asked Nov 27 '25 10:11

FilipR


1 Answers

Using Navigation Drawer is very complicated, Google came up with a better and easier way to implement drawers the NavigationView, and your list should now be a "menu", that you can define in a separate xml file, no need for Adapters anymore. For more info on how to implement it check the official android blog here

like image 77
Mood Avatar answered Nov 29 '25 23:11

Mood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!