我如何使用列表视图没有在我的类扩展ListActivity? [英] How can I use a listview without extending ListActivity in my class?

查看:90
本文介绍了我如何使用列表视图没有在我的类扩展ListActivity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有不同的选项卡的应用程序(在tabhost)。每个标签是一个扩展的活动,具有一定的文本框,事情就可以了一项活动。

现在,我需要我的标签有一个列表视图里面,但是从Android开发者指南中的例子说,你必须扩展ListActivity而不是活动。

基本上,我需要合并这两个教程:

我如何使用列表视图没有 listactivity 上我的课延伸?

我的XML文件:

 < TabHost的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@机器人:ID / tabhost
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    <的LinearLayout
        机器人:方向=垂直
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:填充=5DP>
        < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT/>
        <的FrameLayout
            机器人:ID =@机器人:ID / tabcontent
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            机器人:填充=5DP/>
    < / LinearLayout中>
< / TabHost>
 

解决方案

您TabHost可以包含 ListActivity 为好,因为它从继承活动

但是,你要学会如何在一个活动添加ListView任何方式,按照这些说明情况。这是很简单,做一个活动,在你的XML添加列表视图

使用 findViewById()来让你的的ListView

I have an application with various tabs (on a tabhost). Each tab is an activity that extends activity and has some textfields and things on it.

Now, I need that my tabs have inside a listview, but in the example from Android developer guide says that you have to extend ListActivity and not Activity.

Basically, I need to merge these two tutorials:

How can I use a listview without extending listactivity on my class?

My XML file:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    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>

解决方案

Your TabHost can contain a ListActivity as well, since it inherits from Activity.

But, in case you want learn how to add a listview in an activity any way, follow these instructions. It's simple enough, Make an Activity, Add a Listview in your XML.

Use findViewById() to get your ListView.

这篇关于我如何使用列表视图没有在我的类扩展ListActivity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆