dajver / android-custom-tabs

Automatically exported from code.google.com/p/android-custom-tabs
0 stars 0 forks source link

Attaching an activity to the tabs #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
How can the tabs be attached to activities? It works well if the tabs are set 
to views but there are difficulties in getting the tabs to work with activities.

Original issue reported on code.google.com by noah.am...@gmail.com on 22 Dec 2010 at 8:42

GoogleCodeExporter commented 9 years ago
I figured it out... change the setupTab void to accept an Intent as parameter...

Like this:

private void setupTab(final View view, final String tag, Intent intent) {
    View tabview = createTabView(mTabHost.getContext(), tag);
    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);
    mTabHost.addTab(setContent);

}

... then in you onCreate event on your tabActivity you add following:

Intent myIntent = new Intent().setClass(this, myActivity.class);    
setupTab(new TextView(this), "My tab", myIntent);

That should work...

Original comment by janu...@gmail.com on 3 Feb 2011 at 8:19

GoogleCodeExporter commented 9 years ago
this solution is not working 

Original comment by deepansh...@gmail.com on 14 Jun 2011 at 2:54

GoogleCodeExporter commented 9 years ago
I did this same thing and for some reason Android will throw an 
illegalStateException when setTab is called.

Original comment by kowalews...@gmail.com on 3 Oct 2011 at 2:03

GoogleCodeExporter commented 9 years ago
I figured out a solution to the problem. You need to extend TabActivity not 
Activity to get these custom tabs setContent accepting an Intent instead of a 
View.

Original comment by kowalews...@gmail.com on 3 Oct 2011 at 2:09