> i have a tab host that saves the last selected tab into a preference, and
> loads it again in onCreate(). i add the tabs to the tab host through an
> intent, such as,
>
>
> mTabHost.addTab(mTabHost.newTabSpec("closest").setIndicator("Closest",
> getResources().getDrawable(R.drawable.location)).setContent(
> new Intent(this, ClosestActivity.class)));
>
> the problem is that i only want the onCreate() method of the selected tab
> to
> be called. however, the onCreate() method of the first tab added through
> addTab() is always called, regardless of the selected tab. i figure this
> is
> happening because i'm calling addTab() before i've called setCurrentTab().
> since there's no selected tab set when i call addTab(), it assumes it's
> the
> first one added.
Your theory appears to be correct. addTab() calls setCurrentTab(0) when
you add the first tab, and that will cause that tab's activity to be
launched.
> assuming i'm correct there, is there a way to delay the tab host's
> "initialization" of the selected tab, until i can set it manually? or
> maybe
> i'm missing some other sublety.
Frankly, I have yet to figure out what that sex appeal is of putting
activities in tabs. AFAICT, it results in more fragile code. If you need
the same things to be in a tab *and* in a separate activity, reuse the
inflation and view logic between a standalone activity and just using the
View for a tab's contents. All the tabs-as-activities code seems to do is
launch the activity, then rip the root view out of that activity and put
it in the tab.
So, if you really want control over what happens when, I'd skip the
tabs-as-activities approach, and just put ordinary views in the tabs.
But, that's just me.
--
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---