handling of orientation Changes(fragments) with mutiple backstack via NavigationMenu options - android

I am working on UI which is having NavigationMenu with multilevel fragments. So here is view,i am trying to implement.
So navigation menu have few options each leads to open a ListFragment in FrameLayout, which further opens a List. Same as Option 2.
So i manage to add fragment on Portrait Mode. and using SHOW and HIDE i open next fragments with in same Navigation Open. Even Switching between Navigation Options retains instance of fragment of previous Navigation Option.
But the moment i switch to Landsacpe Mode, it lose all fragment, just show Default Fragment which was loaded First time.
Reason i am using SHOW and HIDE, because i don't want to reload Fragment everytime.
Is there any way to retain fragments in FrameLayout while orientation change.
Link to sample APK is here

Related

Fragment Management - Navigation Drawer

I have a question about fragment management.
I have already programmed a drawer activity based on fragments. After every click on a menu item you will land on an empty fragment.
Now I want to have it so that no matter on which fragment I am on top the same is written. That's about 5 things that are there and depending on the action certain values on the fragment change whatever is there. Like a Information bar.
What options do I have and how do I do that?
Current project scope:
Main activity java + xml
and the Fragments + xml
The main activity is only for the Navigation Drawer. The app starts with a fragment.
How can I implement this?
in you main activity just commit which fragment you want to fill that first view with in onCreate.

Current item in Viewpager changes with different orientation

I have a fragment, which consists of a viewPager in the top of the screen and two buttons at the bottom.
The buttons are for an additional navigation besides the swiping through the pages.
The viewPager consists of about 10 pages with some input fields.
However, when I swipe through the pages and rotate my phone to landscape, the viewPager automatically changes the current item and selects the first page again. Another effect is, that all input data to this point are cleared.
This is really annoying because you have to start all over again.
Is it possible to switch between landscape and portrait mode without this issues?
Some background information:
the app consists of one activity, which is filled with different fragments
a navigation drawer is implemented to choose which fragment will be shown
When you change orientation you are essentially refreshing your activity losing your data such as current page, fragment etc, you need to save your data across the states, i would suggest looking into savedInstanceState.

Adding TabBar using fragments in android

I have a no. of activities in my app.
Now i want to add tab bar at bottom using fragments in android studio.but my problem is that when i open new fragment inside
current tab on button click and then switches to other tab.then when
i come back to same tab it loads the first fragment and not the one
at which i switched to other tab.
Is there any solution for this.
4.I have tried transaction and fragment manager tutorial for this but could not succeed.
Try Bottom Tabs in Fragment State Pager Adapter

How avoid Restarting of Fragment

I am working on Fragments. I am using Navigation Drawer(Sliding Menu) with Action Bar activity.
Navigation Drawer having 4 menu items.Each Menu Item has Separate Fragment like:
Fragment 1,Fragment 2,Fragment 3, Fragment 4.
By default Fragment 1 will be opened. Based on the selection from the menu particular fragment screen will be opened.
If we are opening a same fragment again the fragment is restarting.So here my problem is fragment should not be restarted as it opened again.
I don't have much idea about fragments whether it is possible to avoid restarting the fragment when we are not opening it first time.
So can any body help whether it is possible or not?

Android changing setNavigationMode per fragment is crashing the app

I created the below project so you can see my exact code and what is going on:
https://github.com/CorradoDev/TabsTest/commit/8f054dab2371b791c4061ceb511413f720f65d67
Basically what I am trying to do is hide the tabs for some pages and show them in other pages.
Below is the code I am using to show the tabs in the onresume
if(getActivity().getActionBar().getNavigationMode()==ActionBar.NAVIGATION_MODE_STANDARD){
getActivity().getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
THen to hide the tabs I am doing the below on resume:
getActivity().getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
When I am on the first fragment(nothing in backstack). I can show and hide the tabs on hte second. It gives errors sometimes with changing tabs.
When I am on the second fragment in the backstack and I hide the third fragment. I see the second and third fragment both call the onrefresh but the third fragment does not show.
I am confused on what is going on and why this is not easier.
Below is the error I generally get
03-27 15:26:31.029: E/AndroidRuntime(5505): java.lang.IllegalStateException: Fragment already added: Fragment3{41f2e390 #2 id=0x1020002 fragment3}
I still would like to know why the above does not work. But my fix was to create another activity with the fragment and no tabs. That seems to work well. But I am interested if they did not intend you to change tabs and no tabs per fragment.
I had a similar situation - only that I used NAVIGATION_MODE_LIST instead of tabs. I run into similar issues when I called a fragment from another fragment e.g. click on a list item opening up the item details.
Now I call all fragments from the main activity which allows me to control the set up of the actionbar. Whenever the navigation list should disappear I just call NAVIGATION_MODE_STANDARD when the fragment is called and NAVIGATION_MODE_LIST for the other fragments.

Categories

Resources