I'm updating my app to use fragments instead of activites to later make a better ui for tablet. and as i have minSdk=14 i thought i could throw away support.v4 but now i want a fragment with some tabbed sub fragments. only way i found without the support library is the ActionBar tab stuff. but for tablets i want to have something like this
Left: single fragment (not changing)
Right: changing fragments where some can contain tabs
i want the tabs only visible on the right side and not on actionbar level above both sides. is there a way(thats worth the effort) to do this without support.v4 or should i redo the code i have to use the support.v4 fragment classes that i can use FragmentTabHost provided by support.v4 lib?
As you have a minimum SDK of 14(and I think you're not using a ViewPager?!) it would make sense to use the SDK version of the fragments framework. A FragmentTabHost is a convenience wrapper around a TabHost to make working with fragments as tabs easier. I don't recall seeing an equivalent for FragmentTabHost in the SDK so you would have two options:
Use a standard TabHost and implement your own logic to switch the fragments when the tab changes
Copy the code for the FragmentTabHost and change it to work with the SDK version of the fragments framework. If I remember right the code for the FragmentTabHost is fairly simple and a copy-paste followed by changing the imports should work.
However, it seems you want to use the FragmentTabHost with nested fragments(the fragment tabs being part of another bigger fragment), in this case you need to use the fragments from the support library(along with FragmentTabHost) because the support for nested fragments was introduced in the SDK starting with 4.2 which means that any version between 4.0 and 4.2 will not be able to use nested fragments.
Related
If you are using an Actionbar with Tabs for navigation, should we be using fragments only?
When I'm looking at the developer site, I only see examples where they are switching Fragments, not Activities. The guidelines tell us to use a ViewPager when using tabs, so you should use Fragments to make that work.
The problem is that these fragments will contain quite a lot. They should have other fragments as well. Nested fragments. These are supported when using the Support Library (or targetting api level 17).
My main concern is how the communication will run between the fragments at the bottom of the hierarchy. Will it all run through that one Activity?
You won't have problems. Just treat your fragments as something independent that will be placed in a container. That fragment can have more fragments and so on.
Some people are developing fragment based applications with a single Activity and sometimes makes sense, however I don't like that approach much.
That said, just use all the fragments you need. If you have complex data to pass between fragments you could use the activity to host it and access it in your fragments.
In my Android application I have had to use a tab layout and I want to choose a one from folowing scenarios. they are
using viewPager
using tab host
what are the advantages of viewPager over tabhost. Which one is better. And I'm targeting the android 4.2. Thank You!
It actually depends on what you want and the type of content you are putting in application.
ViewPager:
It is supported in lower API with support library and Sherlock library is always there.
Using ViewPager will give a fresh and distinctive feel to the app. For this you'll need to use fragments. Which are complicated but great in terms of performance and are replacable(a superb feature).
ViewPager
TabHost:
This is achievable using both Fragments and Activities. Although in favour of FragmentTabHost, TabActivity has been deprecated. However if you are not experienced with Fragments, use Activities, but you can always migrate to fragments later. FragmentTabHost
You should check out different tutorials and implement both of them, then decide. You should learn fragments if you embark on using ViewPager. For which, Check this
This blog has numerous examples of tabs. It can help you decide.
I found it very painful to customize tab host such as increasing indicator height, have to create 9 draw batch and customize background and many things.
With tab layout, only one line of code https://developer.android.com/reference/android/support/design/widget/TabLayout.html#setSelectedTabIndicatorHeight(int)
So, I recommend using view pager with tab layout that provides the same UX. Tab host is not deprecated, but it will happen soon, I guess :P
I am newbie with fragments and actionbar in android.
I want to develop application for tablets which has multiple tabs, each tab has Listview in the leftside and the details of the item on the right side
Here is an example of what i want to do.
I don't know which of this is activity and which is a fragment and how to navigate using this tabs and change the content of the listview and the details.
I want examples to navigate using tabs with multipane layout because I searched about that and I found tabs are using fragments and multipane is composed of two fragments and nested fragments not allowed in android.
And I want to know: What is the difference between activity and fragmentActivity?
Fragment Tutorials
Google "android fragment tutorial" and you'll get a lot of results like this:
http://www.vogella.com/articles/AndroidFragments/article.html
Don't stick with only one though because many of them vary just slightly and if you do two or three then you'll have a better understanding of how fragments work (standalone or multipane).
Fragments with Tabs
A great way to see an example of switching fragments is by creating a new android project in Eclipse using the latest ADT. Create a new Android Application Project and when you're setting the name of the main activity you have an option to set the navigation type. Choose tabs or tabs+swipe. This will generate a clean project for you to see the very basics of how to switch fragments using tabs.
Activity vs FragmentActivity
Essentially, an Activity may contain a layout with no fragments and a FragmentActivity may contain a layout with fragments. This answer has a few more details: Difference between Activity and FragmentActivity
I need to do a tabbed layout with dynamically populated listviews inside each tab and I'm unsure which method to use, since tabActivity has been deprecated.
Do I absolutely need to use fragments to achieve this correctly? Can't it be done with Tabhost + an activity for each tab? If so, what's the way around not using Tabactivity?
Thanks
TabActivity has been deprecated in favour of fragments as of Android 3.0 (API Level 11) which isn't very popular yet. http://developer.android.com/resources/dashboard/platform-versions.html
I say develop your app with tabs.
I am doing an application similar to Viber or Linphone, a SIP application basically. I have a main tabhost at the bottom of the screen. And inside each tab I set different activities(for example the historic). I have done this using ActivityGroup. Is that the right approach? As I have seen that ActivityGroup is deprecated, but I dont want to use fragments(most of phones dont support API 11). I have seen the ViewPager component, could be also an alternative? I guess I can change the event onFlip with my finger for the onClick on a specific botton. Am I doing it right using Activitygroup, or should I change to another component?
Usually the kind of thing you are describing can be done using a simple TabActivity.
I'm not sure why you decided to use ActivityGroup, but regarding your hesitation related to fragments - you can use the Compatibility library, which will give you fragment support for older platforms, albeit with some limitations.