如何在Android应用程序中的TabHost下面(不在其中)获取ListView?

时间:2011-03-21 11:22:26

标签: android listview android-tabhost

嘿,我有一个带有两个标签的TabHost,每个标签都有一个活动。

第一个是具有普通textView的Activity。 第二个选项卡是带有ListView的ListActivity。

这一切都很好。 但是,我想在TabHost下面添加另一个列表视图。 所以基本上我会: 标签按钮 标签内容(活动:文本或列表) 的ListView

我的main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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>

但是,我真的不确定如何设置页脚列表的数据。 使用ListView的活动需要扩展ListActivity ... 但我的主要Activity扩展了TabActivity,所以我不知道如何填写列表数据,因为我不能在不扩展ListActivity的情况下使用ListAdapter。 有人知道解决方案吗?

2 个答案:

答案 0 :(得分:1)

固定。 我使用RelativeLayout代替ListLayout

我的最终XML(如果对任何人有用):

<?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>

答案 1 :(得分:0)

使用ListView的活动可以是简单Activity,而不仅仅是ListActivity。因此,只需在</TabHost> ListView下添加到您的xml布局即可。顺便说一句,TabHost也可以包含在普通Activity中,而不是TabActivity

相关问题