Navigation Drawer app behaivour when open fragments - java

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!

Related

Navigation Components: Switch Menu of Navigation Drawer (for logged in users)

I am using the new Navigation Components library. I have a Navigation Drawer in place that works perfectly fine.
If my user logs in I want to change the menu of the Navigation Drawer. Specifically, I want to change the "Login" item to "Logout" from within a fragment.
All the solutions I found online didn't use Navigation Components. So therefore, they recommended something like this:
// Get the navigationView and swap the menu
NavigationView navigationView = view.findViewById(R.id.nav_view);
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.activity_main_drawer_logged_in);
However, this doesn't seem to work in my case (I cannot get the navigationView from within a fragment). How does one achieve this with Navigation Components?
You can access Activity from Fragment through interface:
Create and interface say LoginSuccessListener
Implements this in your Activity
Inside fragment receive this listener inside onAttach
Use it as you needed to update Navigation Menu

Adding A navigation drawer bar to the following code?

I'm fairly new here so I was wondering can someone advise me on a way to implement a navigation drawer activity in the main activity? The code is downloadable from the following links with the source code being the second link and the first link the explanation of how it is done (This isn't my code just to point out):
http://blog.grafixartist.com/image-gallery-app-android-studio-1-4-glide/
https://github.com/Suleiman19/Gallery
It would be very much appreciated and thank you in advance
you can directly implement navigation drawer in your main activity if you are using android studio.
right click on your java folder and go to new->activity->navigation drawer activity.
everything is setup for you (action bar toggle button , lists , icons , onclick methods etc.)
you can edit the list items in menu folder take activity_main_drawer.xml file.

Android - add Swipe View/tabs to only SOME fragments

Currently, my app is using a navigation drawer for my fragments. However, I have 2 fragments that are related, I would like to put these under one heading on the navigation drawer and then have 2 tabs to switch between the related fragments once I select that choice on the drawer.
Is this possible with only one activity or would I have to implement another activity specifically for the tab? I've considered only adding the tabs once the right fragment is committed but that leaves the question of how to remove it once I switch to a fragment that doesn't require the tabs.
I'd also like to avoid having to implement another activity as I am trying to keep the navigation available through my whole app. I'd rather not have to create an identical drawer and then have to keep things consistent between the 2 drawers.
Edit:
So far, I've managed to make a parent fragment that has a viewpager, fragmentpageradapter, and tablayout. Swiping between the 2 tabs does indeed shift between my 2 desired child fragments. However, I am unable to change a textview in one of my child fragments from my MainActivity. I'm guessing the reason why this is the case is because technically, my parent fragment is in view, not my child fragment. Any suggestions to get around this?
Hierarchy:
MainActivity
-Navigation Drawer
--Fragment1
--Fragment2
--Fragment3
--Fragment4
---FragmentPagerAdapter (under Fragment4, tabs)
----SubFrag1
----SubFrag2
Here's how you might use FragmentStatePagerAdapter to swipe across a Fragment:
http://developer.android.com/intl/es/training/implementing-navigation/lateral.html
I hope it help you.

Side bar in android

Does anyone know what this UI element is called in Android, and where to look for the documentation to implement such a layout.
Yup its called a navigation drawer, here is a link to some documentation https://developer.android.com/training/implementing-navigation/nav-drawer.html. Also I believe its one of the standard options when creating an initial project
Navigation Drawer Android Example as follow:
http://javatechig.com/android/navigation-drawer-android-example
its called navigation drawer in android.
to add navigation drawer simply follow these steps-
in android studio go to file - new project - your application name click on next - next - to add an activity scroll down in pop up window - and select navigation drawer activity click to next - type activity name as required - finish.
it will add navigation drawer in your project.
This type of user interface is the most common User Interface used in modern android apps. It is called a Navigation Drawer. The drawer stays outside the screen on the left/right side(where you choose it to be) and comes to action when you click the open drawer button.
For development reference, you can head over to the documentation page.
If you want to add a new such activity to your app, you can click New>activity>Navigation Drawer Activity.
Or when starting a new project, on the Add an Activity to Mobile Screen Page, you can select a Navigation Drawer Activity.

Why use fragments in navigation drawer?

I followed this tutorial about navigation drawer androidhive-navigation drawer and it has used fragments for the list items.
Similarly all sources I found use fragment views for individual list items. I have these issues.
Why use fragments, when we can use an ordinary Activity class?
Going with the link example, if I have Home Activity class implemented before, what should I do to convert it to a fragment?
If Home is the main activity, what happens then?

Categories

Resources