Difference between TabHost and FragmentTabHost - android

I have the following tutorials on creating tabs in Android. It is found here and here.
The first one uses FragmentTabHost and the second one uses TabHost in creating the tab with the use of fragments. I have a difficulty in trying to identify its difference and implication on its performance.
I tried to search but failed to find the answer. Can anyone help me here? Thanks.

I have a difficulty in trying to identify its difference and
implication on its performance.
As it's name suggest a FragmentTabHost is a special case of TabHost specifically built to handle tab fragments. As you can see from the official guide it's quite easy to use the FragmentTabHost with fragments, compare this to the tutorial that you linked to and you'll see the(quite big) difference(which makes it easier to make errors).
There isn't a performance difference other than a performance problem introduced by working with the fragments themselves(which shouldn't happen if they are built right).
It's kind of the same difference between an Activity and a ListActivity, one(the ListActivity) makes it easier to work in a specific scenario(content using a ListView) through some convenience methods(getListView(), getListAdapter() etc).

Related

Android using viewPager vs using tabhost

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

TabHost with Activities vs. ActionBar with Fragments

I've found some discussions related to this issue but nothing clear or definitive.
Building a tab-based application, one seems forced to choose between (A) using TabHost with Activities for each screen, and (B) using the ActionBar with Fragments for each screen. This raises a few questions:
1) Is that dilemma for real, or can one use the ActionBar with different Activities.
2) If the dilemma is for real, why are things set up this way? Is Google planning to deprecate TabHost and the multiple-Activities approach to tab-based navigation? Is there something unsavory about the multiple-Activities approach?
3) If both approaches will continue to be supported, what are the pros and cons of each? If I go with ActionBar+Fragments, will I run into any gotchas down the line? For example, when I want one of my tabbed screens to slide over/pop-on an additional screen/Fragment, will I get funny behavior switching to/from tabs in the ActionBar?
You also have the third option of using a TabHost with Fragments. This makes it to where you only have one activity and multiple fragments as the children.
http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html
I have created a simple example using this class.
https://github.com/marsucsb/nested-fragments
I'm with you. I began developing "Droid Bones" (be sure to use the quotes) before the advent of Fragments. When I began looking at that architecture, it appeared that it would not accommodate my structural requirements. That said, I've found the multiple-activity approach to be very fluid and flexible. My concern is that some of the TabHost documentation appears to have 'gone missing' of late!

Converting Existing App to use Tabs

I have an existing app that is using a Dashboard style pattern where there's a main menu, and clicking icons on the main menu drive start different activities... In order to navigate to a different function, you need to go back to the Dashboard menu and select another icon.
I want to change my application to a tabbed format similar to the one below with Icons:
What type of View is being used below? Is this a FragmentActivity? Also, what is the best approach to go about conversion? I have a bunch of layouts with listviews in linear/relative layouts... Will I be able to reuse any existing code? I want also to be able to use the solution with Android 2.1 and up if possible.
Thanks!
In the image you provided, it looks to be a TabHost that is used (which can be within a normal Activity or a Fragment Activity) and will be available for Android 2.1 and beyond when using the Android Support library. Based upon your description, you most likely have an Activity per each of your items that you will probably want to convert into a different Fragment. This may take a little time, but a Fragment is very similar to a normal activity in many ways, so once you start getting used to it, converting over the old Activities should be a breeze.
If you plan on using these tabs and you follow the Android design UI guidelines, you may want to use the TabHost in conjunction with a ViewPager. There is a great tutorial for this online that also allows for backward compatibility (down to at least 2.1) found here: http://thepseudocoder.wordpress.com/2011/10/13/android-tabs-viewpager-swipe-able-tabs-ftw/
Support library for fragments/viewpager: http://developer.android.com/tools/extras/support-library.html
More info about a TabHost and using Tabs with fragments can be found here:
http://developer.android.com/reference/android/widget/TabHost.html
http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/
You can use TabLayout and a TabActivity to achieve layout in picture. Bad news is these are deprecated as of Android 3.0. Google advises to use fragments instead of these.

Combine tab and listview for android

I'm developing an application for android that is supposed to have three tabs that shows three different listviews. It should look pretty much like this video example:
http://www.androidhive.info/2012/05/android-combining-tab-layout-and-list-view/
The problem i have is that TabActivity is deprecated and i can't found any good tutorials for the Fragment view (which I think is the one to replace TabView). Anyone know how to combine these two views?
You might want to look into ActionBar and Fragments. Maybe the following link could help you out? http://www.lucazanini.eu/2012/android/tab-layout-in-android-with-actionbar-and-fragment/?lang=en

ViewPager can replace ActivityGroup?

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.

Categories

Resources