java - 如何定义 ListActivity 的列表?

标签 java android listactivity

我有一个列表 Activity ,它使用的布局不仅仅包含 ListView 。它还具有一个按钮和一个微调器。我收到错误消息,提示我需要一个名为“list”的 ListView 小部件。

10-15 23:28:36.131: 错误/AndroidRuntime(448): java.lang.RuntimeException: 无法启动 Activity ComponentInfo{rams.rss/rams.rss.RamsRSS}: java.lang.RuntimeException: 您的内容必须有一个 id 属性为 'android.R.id.list' 的 ListView

但是,它已经有一个名为 list 的 listview 对象。我使用了这里的一种解决方案:

Why does my Android app keep telling me I need to define a ListView id when it is already defined?

它仅导致另一个错误,其中添加了带有 .out 后缀的副本。

rams_layout.xml -> rams_layout.out.xml

这是我正在使用的 xml 文件的内容:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
        <Button android:text="Back" android:layout_width="wrap_content"         android:id="@+id/button1" android:layout_height="wrap_content"         android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></Button>
        <Spinner android:id="@+id/spinner1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentTop="true" android:layout_toRightOf="@+id/button1"         android:layout_alignParentRight="true"></Spinner>
        <ListView android:id="@android:id/list" android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/spinner1" android:layout_alignParentLeft="true"         android:layout_alignParentBottom="true"></ListView>

    </RelativeLayout>

关于如何解决这个问题有什么想法吗?

最佳答案

尝试清理您的项目。在 Eclipse 中,这是主菜单中的 Project|Clean。从命令行来看,这是 ant clean

It only caused another error in which a copy with the .out suffix is added. rams_layout.xml -> rams_layout.out.xml

这很可能是因为您尝试在编辑器中将 XML 文件作为 Activity 选项卡时运行 Android 项目。我认为这个问题已经解决了——确保您使用的是最新版本的 Eclipse ADT 插件。

关于java - 如何定义 ListActivity 的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7780906/

相关文章:

java - 从另一个类强制重绘 - Swing

java - 静态方法可以访问非静态实例变量吗?

java - 使用最新版本的 Scala 会出现 java.lang.ClassNotFoundException : scala. Function1$class

android - iOS和Android通用随机数生成器

java - 下载 .csv 文件 Java6

Android:Java线程如何对应原生线程?

android - 在 ListView 标题按钮的 onclick 监听器中获取适配器引用

android - 无法实例化 PlayersActivity NullPointerException 错误

ListActivity 中的 AndroidAnnotations 和上下文菜单

android - 单击android ListActivity中的项目不起作用