How do I get a ListView below (not within) a TabHost in an Android application?
Hey, I have a TabHost with two tabs, each with an Activity.
The first is an Activity that has a normal textView. The second tab is a ListActivity with a ListView.
All this works fine. However, I want to add another listview BELOW the TabHost. So Basically I would have: Tab Buttons Tab Content (The Activity: Text or List) ListView
My main.xml:
<?xml version="1.0" encoding="utf-8"?>
<Line开发者_开发知识库arLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@android: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"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
<ListView android:id="@+id/footerlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
However, I'm really not sure how to set the data for the footer list. An activity using a ListView needs to extend ListActivity... But my main Activity extends TabActivity so I'm not sure how to fill in the list data since I can't use ListAdapter without extending ListActivity. Anyone know a solution?
Fixed.
I used a RelativeLayout
instead of ListLayout
My final XML (if useful to anyone):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/footerlist"
android:layout_alignParentTop="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
</LinearLayout>
</TabHost>
<ListView android:id="@+id/footerlist"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
An activity using a ListView
can be a simple Activity
, not only ListActivity
. So, just add to your xml layout under the </TabHost>
your ListView
. Btw, TabHost
can be included in an ordinary Activity
instead of TabActivity
too.
精彩评论