I am new to this platform and already starting to love it. I am work on a UI for a project which uses the tabhost to display two separate activities using a TabActivity class. This works ok. Now i would like to add a viewflipper to the equation. I am trying to add the tabhost widget to the viewflipper using the addView() method. Eg:
public class Main extends TabActivity {
@Override
public void onCreate(Bundle开发者_运维知识库 savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost host = getTabHost();
host.addTab(host.newTabSpec("one").setIndicator("First").setContent(
new Intent(this, First.class)));
host.addTab(host.newTabSpec("two").setIndicator("Second")
.setContent(new Intent(this, Second.class)));
Button btn1 = new Button(this);
btn1.setText("Second Screen");
flipper = new ViewFlipper(this);
flipper.addView(host);
flipper.addView(btn1);
setContentView(flipper);
}
}
The main motive is to an application with two activities all tabbed. The viewflipper will then flip between these two activities. I am thinking an alternative will be to use xml layout to hold the tabhost and just include it in the view. I am avoiding it for now because that would mean me writing the codes for the two classes again. To round all this up, is there a way to include a tabhost in a viewflipper.
Thanks,
New Guy
You should write it inside the XML instead of hard-coded. it's easier and looks better.
Here i've created a tabhost, which is holding a ViewFlipper of 2 listviews, and another listview in other tab
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/title_text"
android:id="@+id/title"
android:background="@drawable/shape"
android:padding="15dp"
android:gravity="center"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="15dp"
>
<ListView android:id="@+id/listfav" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
<ViewFlipper android:id="@+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/listmain" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
<ListView android:id="@+id/listsub" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
</ViewFlipper>
</FrameLayout>
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
This is how you do it..
精彩评论