Alright, so I have an application that has a tabbed interface. What I would like to know is how I can change the currently active View in the tab, and then when I'm done with that View, go back the the original View, exactly as it was.
A:
For creating the view, what you probably want is something like this:
import android.view.View;
import android.widget.TabHost;
public class MyViewController implements TabHost.TabContentFactory
{
private View myRootView;
@Override
public View createTabContent(String tag)
{
if (myRootView == null)
{
// TODO: Create your view here by...
// 1) Constructing it yourself
// 2) Inflating a layout.xml with LayoutInflater (better)
myRootView = new View(context);
}
return myRootView;
}
}
As for changing tabs programmatically, it is as simple as calling setCurrentTab() on your TabHost object.
Quartz
2010-08-03 05:14:40
+1
A:
You may also want to use a ViewFlipper, defined in xml.
<ViewFlipper android:id="@+id/ScreenSwitch"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<element A>
<element B>
<element C>
</ViewFlipper>
Usage is simple, just find the ViewFlipper object throught findViewById() and request changing:
viewFlipper.setDisplayedChild( idOfViewToSet );
It's then completely up to you, how do you build "tabs".
LordTwaroog
2010-08-03 06:50:07
+1 for ViewFlipper over TabHost. TabHost is evil IMHO.
Qberticus
2010-08-03 07:36:26
The ViewFlipper worked fantastically, thank you for introducing me to this. :)
Chiggins
2010-08-04 20:01:52
You're welcome. I actually use ViewFlipper in my project, even with MapView. But this of course needs some own solutions, I created something like View Managers, so they take care of everything, instead of activities :)
LordTwaroog
2010-08-05 08:23:21