Currently I have a ViewPager with 4 Tabs, each one is a different Fragment. I'm now switching my app to Bottom Bar Navigation but there's a problem with keeping the Fragment state and re-using it later.
The Problem :
Initially Tab_1 is visible. If user selects Tab_2 and then re-selects Tab_1, then I can see that the Fragment for Tab_1 goes through onCreate() and re-downloads the data from the server. With ViewPager I was using the setOffScreenPagesLimit() is there something equivalent with bottom bar ?
Related
so I'm trying to make small application type of thing where it has bottom navigation bar and viewpager2 working in it. But I want it so that in the first fragment page that application loads in, only there viewpager2 is available to work and be able to swipe, when I switch to next fragment with navigation bar that viewpager2 should basically disappear and not work, therefore my logic was to put that viewpager2 in that single fragment and navigation bar outside in main activity for it to be able to be seen in every fragment. But there is a problem, it almost works, I switch to another fragment with bar view pager disappears but when I go back to that first fragment view pager is just gone, disappeared and I have no idea what's the problem. if necessary I can show what I have written. Thanks in advance
I'm making an app that uses a bottom navigation bar (BottomBar) on its MainActivity. A FrameLayout is positioned above the BottomBar. Every time an icon in the bottom bar is clicked, the tab's fragment is inserted into the FrameLayout using FragmentTransaction's replace() function. That inserted fragment contains ViewPager, which results in more fragment launching and caching. Right now, there is only one Activity but many Fragments. I haven't load any data and I'm already receiving a OutOfMemory Exception even after setting the maxHeapSize to 4gb.
What can I do to improve the performance without changing the UI (still have a bottom navigation bar and each tab contains a viewpager)?
Inside my app I am using navigation drawer for my navigation. For each "page" I am using fragments (like showed here: http://developer.android.com/training/implementing-navigation/nav-drawer.html). It works completely fine, but now I want to create swipe tabs. I want to display those tabs only on one of the fragments. Problem is, that tabs are displayed on all fragments, which is ofcourse perfectly normal because tabs are inside action bar. What should I do, to display tabs only on one fragment?
From what I have understood, you are interested in showing action bar only in a particular fragment (not visible when swiping in subsequent fragments). The best way would be to code the action bar in fragment instead of using the action bar in main fragment and then creating swipe views (or sub fragments).
Hope it helps.
I have many fragments inside my activity. One fragment displays Top Books and when clicking on book this fragment is replaced by fragment showing details of clicked book.
Fragment showing top books should have no title in ActionBar, but drop down navigation with categories. However fragment with details of book should have title in ActionBar.
Here comes my question: how should I handle ActionBar changes in my application. Should I configure ActionBar inside Activity or inside Fragments? If in Activity how can I handle all those changes: back button pressing, up navigation button pressing?
Please help, this situation lacks of good examples.
I'd configure the ActionBar in the Activity.
You can override the onBackPressed() method to do different things depending on what fragment is showing.
This reference shows how to handle the up button being pressed, and you can change the logic depending on what fragment is showing as well: http://developer.android.com/training/implementing-navigation/ancestral.html#NavigateUp
I'm building an app that uses tabs with a viewpager and fragments. However, when the user selects an actionbar item, it should show a fragment inside the View where the tabs are displayed.
I tried adding an extra item to the viewpager(For the extra fragment to be displayed), and setting the selected item in the viewpager to the extra fragment when the action item is clicked, it did show the extra fragment, but the last tab remains active below that fragment. Is there any other way to show an arbitrary fragment within the area for the tabs?