Go back to specific Fragment in Navigation Drawer from Activity - java

I would like to know how do I go back to a specific Navigation Drawer Fragment from a activity.
For example:
Navigation Drawer Menu Options:
Home Fragment
Products Fragment (Lists products, the user can click product to edit product activity)
Other Fragment
Now when I go back (Toolbar back button & android back button) from the Edit Product Activity it goes back to the MainActivity which has the Navigation Drawer, but it goes to the Home Fragment. I would like when the user goes back on the Edit Product activity to go to the Products Fragment.
How do I achieve this?
Thanks in advance.

Have you tried navigation component? https://developer.android.com/guide/navigation/navigation-getting-started

I fixed my issue by adding android:launchMode="singleTop" to my MainActivity class in the AndroidManifest.xml file.

Related

need onbackpressed function in MeowBottomNavigation library

https://github.com/oneHamidreza/MeowBottomNavigation
i have implemented bottom navigation bar using above library but when i press back button it is directly closing the app even when i am in another fragment alsp.
please guide me that when i press back button it should come to home fragment and when i am in another fragment the back button should work accordingly to that respective fragment.
when i press back button in bottom navigation bar it should come to home fragment if it is in another fragment other than home if it is in home fragment then it can close app.

Main activity with bottom navigation to another fragment with bottom navigation

Sorry for the vague question. But I'm stuck and I need help. I have this Activity which is my Main and it has bottom navigation with 4 fragments and I have another fragment named Book fragment that also has bottom navigation that hosted 3 fragments. Now in my second fragment from my Main activity, there's a recycler view with click listener. What I want to achieve is after clicking the item from the recycler view it will go to my Book fragment. But my problem now is, the bottom navigation in my book fragment didn't replace the bottom navigation from the main activity. Any guide on how can I achieve this?

Navigation drawer use at another activity only, not in main activity

I have a project containing different activities like: main activity, signup activity, login activity and track activity. Now I want to create another activity which will contain navigation drawer. And the point is "I don't want to use navigation drawer at any other activity".
All the example so far I found at searching # net provide example using main activity. But I don't want to use navigation bar at main activity.
If you are using Android Studio, follow these steps,
1. Right click on app.
2. new -> activity -> navigationDrawerActivity
this way only your new activity will have navigation drawer.

How to disable navigation drawer of activity from within a fragment

I've been looking for an answer to this for a while but I haven't found any answers on the subject.
So I have my Main Activity which containers a toolbar, a nav drawer, and a frame layout (the container for my fragments). So on the start of the activity it starts a fragment to display and I can switch between different fragments and they all have the toolbar and nav drawer because their container is still main activity.
Except there is one problem. I want to make a new fragment and I don't want it to use a nav drawer or a toolbar. I figured out how to disable and hide the toolbar from within that specific fragment but I haven't been able to find out how to disable the nav drawer. The user can still swipe from left to right to open the nav drawer. I don't want them to be able to do that.
Also if I was going to disable it, I need to disable it from the fragment not the main activity because the navigation to this fragment is from a button that's inside another fragment
You can use :
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
This will lock drawer opening on swipe
Source : How to Disable drawer in fragment and back back to correct fragment

Navigation Drawer app behaivour when open fragments

Im working with a Android app that uses Navigation Drawer. This app use the template provided with Eclipse ADT (when you select the navigation drawer template).
I dont understand the behaivour of the navigation drawer very well.
My main requeriment is make a "search" option, I have on the Navigation Drawer a EditText to get the query string from the user. I want that I press search button and open my SearchFragment getting the search query.
I know that I can make this:
Bundle args = new Bundle();
args.putString("searchQuery",searchQuery);
fragment.setArguments(args);
And this for getting:
getArguments().getString("searchQuery");
But I have the next:
MainActivity
NavigationDrawerFragment
SearchFragment
OtherFragments.. (I think this arent relevant in the question)
I dont understand where I can make this steps.
More data:
I have in the navigation drawer class the EditText with the setOnEditorActionListener for the search press.
Any info that I can add I will be add. Sorry my english
Thanks for the help
Navigation drawer is basically a component that show 2 pane in the way that one is the main pane (usually fragment) that is used to show content and the other one is usually a listview that is just used to choose which fragment to show in main pane
so if you want to switch between 2 different layouts you have to create 2 different fragments and then you can add or replace these fragments based on listview's selected item.
You may refer to below link for complete code
http://developer.android.com/training/implementing-navigation/nav-drawer.html
Hope it helps!

Categories

Resources