TabHost with different activities - android

I'm trying to implement an activity which will include TabHost and each tab in it will run\represent a different Activity so if the user press on tab #1 he'll see Activity A and if he'll press on tab #2 he'll see Activity B.
I don't want to use TabActivity as it been deprecated but the new API FragmentTabHost just doesn't seem to be the right answer\implementation (i need to support OS 2.2 and later).
Does anyone have a good idea\example how to do it?
Thx

Don't use TabHost anymore. Use the new ActionBar API with ActionBarSherlock.
To support Fragments down to Android 2.2 you have to use the Android Support Library.

Related

Android 4.2 : Main Activity actionbar hides launching the new activity

I am developing an android application, where in MainActivity i am creating the actionbar with tabs for the application. i do have set listener for Tab click of actionbar which launches new activity in the application...till this everything is working fine.
Problem is : When new activity get created on Tab click, ActionBar of the application (which is created in main activity) is not shown....it shows application icon and name but NO TABS which i created in Main Activity.
I am no using any supported libraries to support previous versions of android. I am using Android 4.2.
Thanks in advance.
A solution can be to extend the onCreateOptionMenu method as shown here.
This provides somewhat guidance on a possible solution, using fragments instead of activities.
I think the first answer to this question might help you:
Android - Switch Tabs from within an Activity within a tab
Particularly the links to the example source code

switching tabs in Android

Basically Android 2.2 and all support older version of tabs, where in we just have to pass the intent for the tab handler which manages loading and handling the activities.
How to do the same in Android 3.0 or 4.0, how to set intent for Tab object? with fragments we can do, but it must be optional right?
Here is the sample code of Tabs in 4.0
ActionBar.Tab tab1 = getSupportActionBar().newTab();
tab1.setText("Hello");
tab1.setIcon(R.drawable.ic_search);
tab1.setTabListener(this);
getSupportActionBar().addTab(tab1);
Any idea, how to add the intent for the corresponding tab?
Basically Android 2.2 and all support older version of tabs, where in we just have to pass the intent for the tab handler which manages loading and handling the activities.
That approach has been deprecated.
How to do the same in Android 3.0 or 4.0, how to set intent for Tab object?
You don't. That approach has been deprecated.
with fragments we can do, but it must be optional right?
Your TabListener is welcome to use fragments, or simply update the content view of your activity.

Changing the deprecated TabActivity

I'm working on an android sample project, which makes use of TabActivity. But as this is deprecated now, I replaced it with the 'Fragment' activity. Now I don't know what to use, to replace,
TabHost tabHost = getTabHost()
which I had used while using TabActivity.
Also, setContentView(R.layout.main)
and setClass() in intent = new Intent().setClass() is giving an error.
You could use Action Bar Sherlock. This open source library gives you an action bar for every Android Version down to 1.6
This enables you to create tabs in the Honeycomb style with the Honeycomb APIs, therefore you do not need to use the deprecated tab APIs.

(Android) Tabbed layout with multiple dynamical listviews - is it possible using tabhost?

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.

Use tabs in Actionbar to launch activities

I have an Android application for pre-Honeycomb devices that uses custom tabs to launch various activities in the app. I'm using Android Compatibility Library and each activity contains one fragment.
I want to develop the app for Honeycomb devices also and I would like to use the tabs in the actionbar for version >= 11 instead of the custom tabs that i use in versions < 11.
My first question is if it is possible to use the tabs in the actionbar for launching activities and if yes, how? I see from the documentation that the main purpose of the tabs is to show/hide fragments and not entire activities.
What other solutions do I have?
EDIT:
I can see that I can call other activities from my implementation of ActionBar.TabListener so I think this would work. Is there a possible problem with this approach?
Yes, it is possible to launch activities from tabs. However, it's a bit tricky because some of the TabListener callbacks are called even when creating the tabs for the first time.

Categories

Resources