【问题标题】:List View and ListActivity question in AndroidAndroid中的List View和ListActivity问题
【发布时间】:2011-06-27 01:28:16
【问题描述】:

我正在尝试使用列表视图和列表活动。我的代码很简单,这里是我的 java 和 xml 文件。 MyRecords.java 文件是:

public class MyRecords extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myrecords);
               .
               .
               .

myrecords.xml 文件是:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:id="@+id/myrecords">
</TextView>

我已将此添加到清单文件中:

    <activity android:name=".MyRecords"
        android:label="@string/myrecords_title" >
    </activity>

在我的主要活动页面中,我有一个与 MyRecords 对应的按钮。 问题是,只要我按下按钮,应用力就会关闭。 感谢任何帮助让我知道这段代码有什么问题。 我必须提到,当我有活动而不是 ListActivity 时,代码没有问题。

感谢您的帮助。

TJ1

【问题讨论】:

    标签: android listview listactivity


    【解决方案1】:

    需要为 ListActivity 提供一个布局,其中包含具有正确 id 的 ListView(我认为它是 android:id/list)。

    【讨论】:

    • 它是android:id/list。 @TJ1 - 见docs here
    • 非常感谢,就是这样,所以我改了:
    • 我把 android:id="@+id/myrecords" 改成 android:id="@android:id/list" 并且还在xml文件中添加了一个ListView,再次感谢。
    猜你喜欢
    • 2020-12-15
    • 2012-01-26
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多