I've been trying to create an app that uses the FragmentStatePagerAdapter, TabLayout, and Fragments. My goal is to have an app that functions as described below.
[App]-->
-->[Tab1 Default View]-->ChildFragment-->ChildFragment
-->[Tab2 Default View]-->ChildFragment-->ChildFragment
-->[Tab3 Default View]-->ChildFragment-->ChildFragment
So, when the app loads, it would show Tab1 by default. Tab 1 would have it's "Root" view, and when I load a new "screen" from within it, it would nest the screens inside the Tab1. So if Tab1's title was "Tab 1" it would show that by default, but then if I click a button to load a new screen in tab 1, it would show the title as "New screen" and the back arrow would appear, which on click would take me back one level to the root view.
I've tried following the tutorial here...
https://tausiq.wordpress.com/2014/06/06/android-multiple-fragments-stack-in-each-viewpager-tab/
However, it's FULL of errors and will not even compile in Android Studio newest version. Can anyone provide a short and sweet example project or even a link to a working example that I can follow?
My app has always worked fine using ActivityGroup class, but since it has been deprecated since Api 13 I feel I REALLY need to update my app so it continues working in future Android versions.
Help please!?!?!
Related
I am building a Xamarin Android app and need to make a design choice. I am still rather new in Android development, and don't know any other developers in my area personally that I can ask for help on this matter.
The app has a "BottomBar" with several buttons / tabs. If a button is clicked, a new screen should appear.
All 4 screens contain a lot of data, mostly lists (or RecycleViews?) of images with text and when clicking on a listItem or similar, an associated detail screen should appear.
At this point I wrote code that loads new activities when I click on one of the bottombar buttons. E.G., btnA loads activityA, btnB loads activityB and so on. The BottomBar is regenerated in each new activity and also keeps track of its instance State, so if I am in activityA and click on btnB, ActivityB loads and in activityB btnB is highlighted as the active tab, without me having to write a single line of code. Basically, this is working great out of the box.
I am wondering however if I should add a big fragment container in a host activity, and load different fragments in that container on BottomBar button clicks instead. Maybe this approach has a performance benefit or some other benefits that I am not aware of as yet. As for now, we don't have any intentions to create a tablet version, we only want to create a mobile version of the app. I understand that I can reuse fragments with a bigger screen estate (tablets), but this should not be necessary.
Again, everything is working ok as it is, but I am only at the beginning of building the app, and would like to make good design choices early.
The BottomBar component that I am using (Xamarin c#):
https://github.com/pocheshire/BottomNavigationBar
The above version is a port of this (Java):
https://github.com/roughike/BottomBar
Any advice is appreciated...
Sorry for long waiting.
If you want to follow the path that Google recommends in their guides that you need swap the fragments in the container by pressing the tab.
Link to Google guides
I am creating my first ever android app. For this I have followed this example to create a very nice sliding tabbed layout.
It's very good, but there is a small problem.
I have created about 5 tabs, each supported by 5 different fragments containing their own controls. When I exit the app with back button and start it again, all my controls on each page retain their state (using my Singleton parameters class). But on each reopening, the app starts with first tab selected. Even if I was working on 5th tab and existed from there, the app shows the first tab only.
I could keep the tab index in my singleton class, but how do I set it such that the app always opens with last open tab using something like setSelectedTab(tabIndex)? And where should I call this method?
Thanks a ton in advance for the help.
I am working on a simple project with NavigationDrawer in Android. The drawer has three items Game, Settings, About Us. The app loads the Game fragment first. Let us say in the Settings fragment there is on control to select the Level. Say I select level 3. Now whenever I go to Games fragment again the game should be loaded with Level 3.
Using interfaces and implementing the methods calls the Game fragment immediately. What if i have other settings to change? I want the Game with level 3 only when I click Game in the drawer.
Please help!!!
You can find the image here : http://i.stack.imgur.com/DXxFO.png
I'm working to clone an iOS app that uses a UITabBarViewController as the "main/outer/root" UIViewController. Each of its tabs has a UINavigationController as the root to manage a navigation stack of UIViewController instances.
I am trying very hard to do 2 things:
Replicate the functionality of the iOS app.
Do so in true "Android" fashion (i.e., not forcing an iOS paradigm in a non-iOS world).
I've searched around a good bit, but this topic seems to have been changed a lot over the past few years. I tried a solution that had a single Activity that managed everything, but that required maintaining separate back stacks, and seemed to get a thumbs down from most users around here.
Currently, I have a solution that is "sort of" working. As I understand it, my current setup is:
A single, BaseActivity class that extends ActionBarActivity.
All activities in my app (only 2 thus far, but slated for 5) extend this class.
This base activity loads a drawer.xml layout, which has an android:support.v4.widget.DrawerLayout as its outermost item.
Inside of this is:
A FrameLayout, which is the container for my fragments.
A ListView, which is the drawer itself.
Based on my testing of the app, this setup gets me most of what I want.
When I "navigate" (using the drawer) to a different activity, the correct activity is loaded.
When I "navigate" to a "deeper" fragment (via on-screen controls), the correct new fragment is pushed and I've overridden onBackPressed() in BaseActivity to correctly pop the back stack if appropriate.
The problem I'm encountering is this:
The app is launched and "Activity 1:Fragment 1" is displayed. I click on an item to move to "Activity 1:Fragment 2" (which works well).
I use the drawer to launch Activity 2, and "Activity 2:Fragment 1" is shown. So far, so good.
I use the drawer to go return to (at least that's my intention) to the existing Activity 1, and "Activity 1:Fragment 1" is displayed.
I've looked into Activity/Intent launch flags, but I'm not sure I really get what's going on. So far, my reading has led me to try the following steps:
When switching Activites, setting its flag like this:
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
In my AndroidManifest.xml, setting Activity launchMode like this:
android:launchMode="singleInstance", or like this
android:launchMode="singleTop"
An odd, additional problem I'm facing is that launching a new Activity doesn't seem to create the Activity back stack like I expect. When I move from Activity 1 to Activity 2 (ignoring the lack of fragment back stack maintenance for a moment), pressing the back button from Activity 2 closes the app, which confuses me.
Is there a single, current best practice for this type of app structure/navigation?
the good approach is to have 1 activity and handle the back stacks manually as Android has only 1 stack. I've done this several times and finally I created a library called Tab Stacker that does the job: a fragment history for each tab.
It is open source and fully documented, and can be included easily with gradle. You can find the library on github: https://github.com/smart-fun/TabStacker
You can also download the sample app to see that the behaviour corresponds to your needs:
https://play.google.com/apps/testing/fr.arnaudguyon.tabstackerapp
If you have any question don't hesitate to drop a mail.
Is it possible display one tab or another in android dynamically?
I am trying to make an app with 3 tabs but sometimes is possible that one or two tabs will not have content (not buttons or data in activities) so I want just show the activity which has data or one of both with it.
I want to keep the possibility that the user navigate to tabs without content but I want to show firstly the tab with it.
I am following this tutorial: http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/ to do the tabs. I mean, if you need my code to make any modification or add anything. For the moment I just want to have an example to show it and after that start adding my code, which already works in an older app.
You can move to the tab by using
viewPager.setCurrentItem(item_position);
getActionBar().setSelectedNavigationItem(item_position);