I have some concerns with how to approach this:
background:
Main app view has a TabHost that displays different activities.
From these activities more activities can be launched that is not part of the TabHost.
What I want to accomplish is to keep the TabWidget on top of these activities that is not part of the TabHost.
One way I'm thinking is to have these new activities' layout contain a TabWidget made to look the same as the real thing. But it feels hacky and view switching animation may be complicated.
Another one is to tap into the LocalActivityManager in the TabHost and launch the activities using it, and add the view from the returned Window to the TabHost's tabcontent.
Any suggestions welcome!
Thanks.
actually found solutions to this with fragments and without.
with fragments:
Design Application with fragments
without fragments:
basically this UI style fits nicely with fragments, otherwise you have to roll your own ActivityGroup to manage the multiple activities.
How to start an activity in a tab?
Related
I am developping an app with an activity which switches between a few fragments. I was wondering if it is possible to have one of this fragment with tabs in the action bar, but not the other ones, knowing that, in general, the activity is tabbed and the tabs switch between fragments.
In a nutshell, I want an activity with a few fragments, and one of this fragments should have tabs to browse between other fragments, is that possible?
Ofcourse it is possible, take a look around StackOverflow, there are a couple of questions already.
Instead of normal TabHost your should use FragmentTabHost and because you will have fragments inside a fragment, you will have to use getChildFragmentManager() instead of getFragmentManager().
Adding tab inside fragment
Nice post Marko! I was just typing up basically the same answer. Here is a link for the documentation on Nested Fragments hope that helps as well
I am creating a tabbed application and the main activity for one of the tabs is a listing of departments. When you click on a department it starts a new activity that lists the documents in the department.
My issue is when it shows the document listing, the tabbed view goes away. And I would like to keep the tabs on the top constantly. I have attempted to extend the TabActivity to each of the activities that are started under the tab, but then the listviews create over eachother.
I have also attempted to create the tabs without a tablistener starting an activity, so I can only create the listener if it is the first time the tab is called, but that is not allowed.
Any help would be appreciated, maybe there is some method I am completely missing?
Thank you!
And I would like to keep the tabs on the top constantly.
Then you should not be starting an activity when the user taps on tab. Your tab contents should either be fragments or something else manipulated by your TabListener. The concept of activities being the contents of tabs is now deprecated (and, IMHO, was a bad idea to begin with).
I have attempted to extend the TabActivity to each of the activities that are started under the tab, but then the listviews create over eachother.
You will notice that TabActivity is deprecated, specifically for the activities-as-the-contents-of-tabs concept.
I'm trying to create a layout that has a stationary footer with activities that slide behind it. I've been told to use Fragments, but that would mean that I would have to convert my already existing Activities to Fragments - right? Here is a diagram of what I'm trying to achieve: http://i.imgur.com/K8Iao.jpg
What I think #TarunMaheshwari is trying to say is that instead of having 3 activities (eg. classes with extends activity), replace it with extends fragment (obviously there are other minor changes you might have to make for the code to work) and then create a main activity (with extends FragmentActivity) that has the static footer you want which can call on the 3 different fragments.
Recommended readings:
http://developer.android.com/guide/topics/fundamentals/fragments.html
http://android-developers.blogspot.ca/2011/02/android-30-fragments-api.html
I believe using fragments is the right solution for your app. However, from what I understand from your question and comments, you really want to avoid using them. To use activities instead of fragments, implement a Tab Layout with a Tab Host and Tab Widget as explained in this tutorial. This solution allows you to use the tabs to switch between activities.
To align the Tab Host to the bottom of the screen, have a look at this tutorial.
I'd like to show a different fragment in a TabHost, for every tab. But
it seems that there's no easy way to do this. TabHost can only accept
A. Views or B. Intents that launch Activities when the user selects a
tab.
Going with A means that I have to initialize every fragment and load
them into container Views that are given to the TabHost. But I want
these fragments to load only when needed - when the user selects their
tab that is.
Going with B means that I load the fragments into separate Activities
for each tab. But I'd like the fragment to be able to reach the
"original" parent Activity, not just some shell Activity that hosts
them in a tab content.
Am I missing something? Is there a way to manage fragments with
TabHost properly?
Some hits here:
fragment Support with Tabhost
Android 1.6 & Fragment & Tabhost
For what I understood, "link" a fragment inside a TabHost isn't allowed, you need to create activities that include your fragments and then call these activities from TabHost.
EDIT
the "official solution" from Google, and with nice animations.
How can I add a dynamic view in a TabHost.
I have two tabs i.e. TabA and TabB. In TabA, I have 2 buttons and I want to set the layout (I have 2 different XML layout's) of TabB, depending upon the button pressed in TabA.
Can anyone help me.
Thank you!
That depends on the implementation of your TabHost. Have you used Activities or Views as Tabs?
Generally in your TabActivity you could use getTabHost().getTabWidget().getChildAt(index) or another method to get the view of a Tab.
If you use Activities as the children, you could also start a new Intent with your ActivityGroup and set a new view within the onCreate() method.
If you have problems finding examples for ActivityGroups with TabHosts, I can provide you a code sample showing you how to do it and also how to change the view within another tab by clicking a button.