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
Related
So if for example I had 4 fragment managers, would there be 4 seperate back stacks to handle?
Im looking to create a tabbed application that uses a bottom nav bar to switch between fragments. But within each tab the user can progress through to different areas of the app. I need it so that no matter how far they get in to a tabs flow, if they clicked on another tab, then came back to the previous tab, they would still be at the same place they left off.
So would using multiple FragmentManager instances (one for each tab) solve my issue?
In my case I have 4 fragments, one for each tab. So if im on tab 1 and go to fragment 4 in tab 1, if I then tap tab 3 and go to fragment 2 in tab 3, if i then go back to tab 1, i should still see fragment 4 of tab 1. But im not sure how to set this up.
You should be fine using two Fragment instances for the tabs in the nav bar, and use each tab Fragment's getChildFragmentManager() method
I want to create application which structure can be simplified as this:
Where Events tab has static content in our stackoverflow world, and is not reloading when app is working. So we can simplify it as a ViewPager.
Problem is with reloading Home tab, because when we set option in Drawer, accurate fragment should replaced Home tab.
Question
So here is my question, is it something similiar to ViewPager which replace current window from right side ? Because I replacing fragment in view pager is quit hard, so I want to replace home fragment in traditional way.
I`m not sure what your problem is. You don't want to update home fragment, you just want to replace it, so replace it and notify viewpager adapter for your change, save preview fragment before that and override back button press logic to replace again whit backuped fragment.
I am developing an app that uses ActionBar navigation, I have 3 tabs (I dont use tabhost) as image below:
In the first tab, a fragment named FragmentListItem will be shown, if I click on Item1, FragmentListItem will be replaced by another fragment named FragmentItemDetails, that shows details of the selected item.
My problem is, when I select Tab2 or Tab 3, and then I reselect Tab1 again, what I get is not FragmentItemDetail anymore, it is FragmentListItem instead.
So, why is that? If I want FragmentItemDetail still be there instead of FragmentListItem, how to do that?
Moreover, when I press Back button (when Tab1 is selected), I want FragmentListItem will be shown again. I realise that Fragment class has no onBackPressed method to implement.
There are different solutions to this issue.
One possible solution is to use an own FragmentManager for this tab. This is possible with the getChildFragmentManager() method of Fragments.
Another solution could be a flag to identify which Fragment was shown as last on Tab1. If you know which Fragment was shown as last you could show this one by search this Fragment in your BackStack with the findFragmentByTag(tag) method of FragmentManager.
But I recommend you to try the first Option. If each tab has his own stack you have less work with your BackButton.
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.
I am creating an android application, in which I used tabs. There are six tabs which shows different activities. Last activity in tab have one button(clear). When we click on button, I want to clear all views in tab. Is it possible. Please guide me.
Just Call another blank activity inside the onclick event of the button.
Try use Fragments instead of Activity for every tab,
this way you could clear the tab much more quickly with FragmentManager