Can a navigation Drawer be declared on a Fragment? - android

I got a navigation drawer on the activity of my app, but once I get the fragment parts of my app running (through a fragmentActivity) I have trouble programming a navigation process over there. I want my users to be able to navigate from one fragment to another fragment using the navigation drawer, making life easier.
Does anyone have a solution to this?

I think what you want is a ViewPagerIndicator, and to use a ViewPager with a FragmentPagerAdapter to page your Fragments.

Related

Adding a navigation drawer to an existing project

I'm a beginner in Android. I have a project with multiple activities and I need to add a navigation drawer to this project instead of a normal menu. I added a new navigation drawer activity, but it doesn't show in my previous activities.
Should I add something to my existing activities?
All the tutorials I have watch use fragment while I use AppCompatActivity.
So I don't know how can I add it to my project.
Can you help me, please?
to do that, you have to use fragments instead of activities. fragments are easier to work with navigation drawers than activities. 1st you have to create a main activity for navigation drawer. Change your other activities to fragments. Then you can have navigation drawer in all the fragments. Refer below video it has everything you want. if there is any problem ask. https://www.youtube.com/watch?v=-SUvA1fXaKw

get data from one fragment to another fragment in navigation drawer in android

I develop one android app with navigation drawer.in that navigation drawer using fragment for each item pages. I want to get data from one fragment to another fragment in navigation drawer. How to solve this task?
It does not matter if it is in Navigation Drawer. Use the same method to pass data between fragments as in developer docs
https://developer.android.com/training/basics/fragments/communicating.html
other link as mentioned in comments seems good too
https://www.google.co.in/amp/s/www.journaldev.com/14207/andr‌​oid-passing-data-bet‌​ween-fragments/amp

Android menu option problems in fragments

I am developing an application which has a navigation drawer with 9 fragments.
Two of nine fragments have tabs(4) interface implemented. Each tab has its own menu option and each fragments (other than with tabs) have their own menu options.
Now the issue is,
When i access or switch a simple fragment(without tabs) from the navigation drawer then its menu options and working fine.
BUT
When switching from a tabbed fragment after accessing , its menu options now appear on every other fragment in the navigation menu.
For example
I access and switch from fragment "A" ->everything goody including all menu options
I access and switch from fragment "B" (with tabs) then all the other fragments have its menu options.
If I didn't explain my problem effectively then do ask me again in the comments. I have been stuck with this problem since a week. Maybe a small problem or something else but do need some help from the people here.
////update//
SetHasMenuOptions implemented in each fragment. All fragments working fine except the tabbed ones
The main problem is, after accessing tabbed fragments all the menu options of other fragments are replaced by the tabbed menu options.
3 posting a question through my phone cant post code sample.
Actually first i had problems like this with every fragment but then i implemented sethasmenuoptions
And menu.clear() in each fragment and every fragment seems to work
Like it should except the tabbed ones
Hope this info helps
Thanks
Use transaction.addToBackStack(null) while fragment transaction and in layout set background colour to the fragments .

Navigation Drawer and Fragments best practice

I am going to use Navigation Drawer in my app. I have read about most common approaches of building such apps, a lot of people suggest to change only framgent while selecting different items in navigation drawer. So instead of openning new activity it is better to change fragment of current activity ? Am I right ?
The problem is that I have main activity with two fragments now.
What is the best practice to follow in this case.
To open new activity on item click in navigation drawer ?
To use nested fragments, because my activity already has 2 fragments, so maybe to create some wrapper fragment to nest these two fragments or more if it will be another page.
Please suggest what is the best practice to implement this design pattern in my case.
Technically, the correct way is to change only the fragment while selecting different items in navigation drawer, which would be possible even with only two fragments. There is usually no reason to use nested fragments.
Obviously, there are many ways to do it, and from the UI perspective, there are many possible designs (Navigation Drawer, tabs, sliding pager, etc.)

Android Navigation Drawer Design

I have an existing application that has about 25 activities that are navigated to from a "dashboard". I would like to switch and start using the Navigation drawer and fragments. I have gone thru the Nav Drawer design pages online and the example app. My question is what is the best way to convert (structure) my app to fit the Nav Drawer pattern. If I switch my activities to be fragments and use a main activity to replace each fragment as navigation happens, but not sure if that is good b/c for a tablet layout, I might want multiple fragments on my view and not sure if this will limit me. If I go with the other direction I was thinking, keep all my activities and just switch the necessary ones to fragments for tablets but I would need each activity to create the navigation drawer (I think ?) which in my case the drawer is dynamic based on server data. Any suggestions would be great.
Thanks
Brandon
Navigation drawer has to be created for each activity, although you could inherit Activity and create a parent class that handles navigation drawer specific code if code duplication is a concern.
Using a drawer does not limit you to use one fragment per screen, just listen to onClick in drawer and initiate as many fragment transactions as you need.
When it comes to structuring your app, there is no universal advice, I would recommend you to watch Google I/O 2013 talk - Structure in Android App Design. Navigation Drawer is kind of the main theme of the talk.

Categories

Resources