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.
Related
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.
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.
I have developed this application which uses an ActivityGroup to switch between Activitys in a tab. I have downloaded the newest AdMob SDK, forcing me to use a targetSdkVersion of 13 instead of 8. Because of that, I get the warning that ActivityGroup is deprecated.
What is the new way of switching between Activitys in a single tab? I'd rather keep my minSdkVersion at 8. And are there any examples of it?
What is the new way of switching between Activitys in a single tab?
There is no "new way of switching between Activitys in a single tab". The closest thing to a "new way" is to not use activities-in-tabs, but to use fragments-in-tabs, or tabs in the action bar (that alter the UI, such as by changing fragments).
The JavaDocs for TabActivity show how to implement fragments-in-tabs.
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.
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.