Android menu option problems in fragments - android

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 .

Related

Android Jetpack Navigation proper back stack with BottomNavigationView

OBS: Though still no first class support (as of writing this), Google has now updated their samples with an example of how they think this should be solved: https://github.com/googlesamples/android-architecture-components/tree/master/NavigationAdvancedSample
The Android Codelab for Navigation does a good job describing how to use the architecture component Navigation together with a BottomNavigationView. But let's say I have 2 tabs in the BottomNavigationView, Tab1 and Tab2. And let's say that in Tab1 you navigate through the fragments Frag1 --> Frag2. Now, whenever I go to Tab2, and then back to Tab1, the fragment back stack of Frag1,2 is gone, and replaced with the starting point Frag1 again.
What do I have to do in an app so that a BottomNavigationView together with Navigation keeps its back stack intact even though I change tabs? And, also keeping the back/up button behaviours in sync with the guidelines.
Previously I've done this with the use of ViewPager and managing the back stack my selfe, but that doesn't feels like the right approach with the new Navigation.
Thanks in advance!
Edit:
There's a more elaborate answer here.
The major reason is you only use one NavHostFragment to hold the whole back stack of the app.
So the solution is each tab should hold its own back stack.
In your main layout, wrap each tab fragment with a FrameLayout.
Each tab fragment is a NavHostFragment and contains its own navigation graph in order to make each tab fragment having its own back stack.
Add a BottomNavigationView.OnNavigationItemSelectedListener to BottomNavigtionView to handle the visibility of each FrameLayout.
If you don't want to keep all the fragments in memory, you can use app:popUpTo and app:popUpToInclusive="true" to pop out the ones you don't want to keep.
This is currently not supported in the new Navigation Architecture. I was also pretty bummed by this, as it is a very basic feature in today's apps, and a lot of the apps are now using the bottom navigation. There is a running thread, if you wanna keep an eye on it. They are saying they will come up with a long term solution for this, but for the shorter run, they are gonna give a sample on how to tackle this. https://issuetracker.google.com/issues/80029773#comment25

Tab Layout with a Navigation Drawer and Toolbar

I've been trying to get back into something I was working on before and got stuck on. I found a picture on the google developers site that has what I'm trying to create.
https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B9PCOJnbdRP6QW9pN01mS2k4UFU/patterns_navigation_twolevel4.png
Basically, I have one activity, that has several fragments that you can navigate to through the navigation drawer that pulls out from the side. I'm trying to have one of those fragments be a fragment that has a tabbed layout, which works fine, except the tabs don't show up since the toolbar created in the activity. How do i do this?

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.)

Can a navigation Drawer be declared on a Fragment?

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.

Fragments Within Fragment Tabs

I'm building an application that requires Tabs, which are now deprecated. The dev guide says to use Fragments to replace the tabs instead. However, my application needs to have fragments within each tab, which means fragments inside fragments, which isn't allowed. Does anyone know of a possible work around for this?
While the action bar support for tabs is designed to make it easy for the contents of a tab to be a fragment, that is not strictly required. You could use ViewFlipper, repeated calls to setContentView(), or something to arrange to change other stuff when the action bar tab is selected.
Prior to the native action bar (Android 1.x/2.x), either stick with classic tabs, or use something like Action Bar Sherlock to get an action bar and tabs.
I fake tabs by having a "tabs" fragment across the top that contains multiple toggle buttons. Below that I have a merge view containing a separate fragment for each tab.
I respond to taps on a toggle button by toggling the other buttons "off", showing the fragment for that "tab", and hiding the others.
its little late , but yes you can :) here's an example
but for fragment inside fragment inside tab isn't an android native way, you have to start a new fragmentActivity if you want to show detail of fragment. you can but is not an android way !

Categories

Resources