View switching between MaterialDrawer layouts - android

I need to create two MaterialDrawer for the same activity and switch between them. But I need that items be updated when the Drawer is being displayed on the screen.
With the properties we have for MaterialDrawer, the changes between one drawer layout to other only can be visible after the drawer is closed and you touch the drawer toggle again.
Is it possible to do a refresh in the layout, do a invalidate or do a notify in the changes during the display of the drawer, when switching between drawers, for the changes to be displayed on the fly?
Thank you,
Alexandre Bianchi

The MaterialDrawer comes with a easy to use API which will allow you to modify the items, shown in the Drawer at runtime, without the requirement of creating a new Drawer object.
You can remove the current items in the list at any time via the removeAllItems method. https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L747
And you can easily add new items in the same style via the addItems method: https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L756
These changes will directly reflect in the UI.
For some more complex usecases you can also look into the source code used for the AccountSwitcher which will switch 2 lists in the Drawer and animate them: https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L1348

Related

What is the correct way to approach ViewPager and Fragments when number of fragments are more than 50 but each of them has same layout and methods?

I am making an app which has a navigation drawer. This navigation drawer has 50 menu items. These items have the same layout, same activity but different data.
I want to implement ViewPager in my app so that the user could swipe left and right (manually and automatically).
Issue: I am facing an issue of how to implement this. The activity (for these menu items) has its own methods and functionality. A ViewPager can slide fragments but my issue is that since all of these menu items have the same layout and functionality then it would be much better to use one fragment whose data change with swipes for each menu items.
I don't know how to approach this. Please guide me.
You can do it by using a recycleView,and you will need an arrayAdapter which will help you adapt the data accordingly and you will need to have a separate class that will have all the data you want, you can also have different constructor in that class. You can check this to know more https://www.codexpedia.com/android/a-very-simple-example-of-android-recyclerview/

Understanding android navigation drawer and fragments

i'm quite new to drawer material and i have trouble understanding some things:
I need to create an Activity with a Fragment on it. Different selections on the Drawer must replace the current Fragment with another one, but is the Drawer something in the fragment or it is one for the activity itself. More specifically is the Drawer living in the Fragment and if not is it possible to create it in the Fragment. I am asking this cause i see that when initiating the Drawer you need to fill parent activity. Also when i tried to use the Navigation Drawer template in Android Studio i didn't had the Use a Fragment checkbox.
There are many ways to achieve what you want. But I think the simplest way is:
1) DrawerLayout view should reside in the activity (probably as the base layout).
2) When you click on an item in the draw 2 things happen:
The fragment is replaced (you have one layout to contain the fragment and you just replace the fragment in it).
The items inside the drawer update (if you are making a list you would simply set the data and call notifyDataSetChanged().
Don't forget to save your state so it can recover in case the Activity is recreated.

How can I make a multi-level(more than 3 level) navigation drawer in android?

I am developing an android application where I need to put a navigation drawer which would have more than 3 levels.
What I want to do: If I click one item of my list in the drawer, a whole new list comes up in the drawer. This new list should also do the same when items of this list are clicked. This could go on for many levels.
What I have done till now: I am keeping an expandable list which expands when I click on any item. This design doesn't allow adding more levels.
Application which have similar drawers: svpply (please have a look at this application, it has a similar drawer)
I am a newbie in android development, try to add details to your ideas.
Thanks!
Have a single drawer keeping a FrameLayout.
Make all your list as ListFragment
Make Fragment Transaction on FrameLayout when a item is clicked.

Update NavigationDrawer List onOpenDrawer

I have a navigation drawer whose list can change based on an action in the current activity. After making a change in the current activity I update the list immediately in the code. I opened the navigation drawer, but no change has been shown. However if I proceed to change activities and open the drawer again, the change in the list is now updated. This leads me to believe that after the first time the Navigation Drawer is created or called, the drawer is reusing the same view instead of being destroyed and recreated.
I am looking for a method with Android that would be equivalent to onOpenDrawer, however I do not see one in the docs. In the docs there is onDrawerOpened(View view) which is called after the drawer has already been opened. I also have the option to call openDrawer(View view) which then annimates the drawer open.
I am wondering if there is a method that I am missing and that I can override which will allow me to update the listview being displayed in the navigation drawer.
Thank you in advance.
Calling of notifyDatasetChanged() still applies to ListView adapter, regardless of ListView parent.

Layout setup with fragments

I've just started converting my apps to use fragments. I have a ListView activity and a "Details" activity, which the user goes to after selecting an item in the Listview. I've converted them to fragments successfully, however, I have a header in the layout of each activity. The ListView has a "reload" icon in the header, but the header in the details does not.
Everything works fine when I'm viewing the app in portrait, but I have a layout in the "layout-land" folder which contains both fragments, so, when viewing in landscape, you see both the ListView and the "Details" view. The problem is the header layout is shown in both fragments.
My question is what is the best practice for covering my layouts to the new fragment setup? I'm thinking, instead of having the header in each fragment's layout, I just add it to the layout that contains both fragments?
Sorry if this is just obvious question, I'm still trying to wrap my head around the whole fragments paradigm.
That's why the use of ActionBar is recommended. If you include an action bar in your app with a refresh button , users will know (and learn) to use that button. The onClick implementation is all yours and you could refresh the list adapters accordingly. There is no need to then build these UI elements in all your controls.

Categories

Resources