I would like to know if its possible to have different tabs on the top and bottom that lead to different activities when clicked. Googled it but didnt find anything about it
The good thing with Android is that almost everything you want to do should be possible. If we were to alter your XML we would change it to something like:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs_top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
Notice that I've changed the ID's of the TabWidgets.
This is only half of the problem. The other half is how the source code for the core class TabHost
should altered to accommodate this change.
You can review the source of the original TabHost
here. Looking at the source it's pretty obvious the code has a single mTabWidget and this is initialized using the very specific ID = tabs
(com.android.internal.R.id.tabs
). We've changed the ID's so we should be mindful of this.
So, how can we alter the original source? One approach is to make our own class and extend the core TabHost. This will not be easy because half of the functions and members inside the original TabHost are private
(why aren't they protected
?!?). Anyways, since you have the source code and it's pretty simple, it's possible to do it.
Let's say your new extended class is MyTabHost
(potentially place it in the same package as the original TabHost just so you can access variables/functions which have no private
or public
), then you can replace in the XML the word TabHost
with MyTabHost
or com.yourpackage.MyTabHost
actually) and then your class will be used in the XML instead of the original.
From looking at the source code, it's obvious that this feature isn't supported by default. But - I think that if you really want to make it happen, you can see a way.