每当我尝试开始此活动时,我都会收到此错误:
01-31 02:19:19.558: E/AndroidRuntime(1318): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.prva/com.example.prva.ListView}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
列表活动:
package com.example.prva;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
public class ListView extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
fillData();
}
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = DatabaseManager.getAllData();
startManagingCursor(c);
String[] from = new String[] { DatabaseManager.TABLE_COLUMN_ONE };
int[] to = new int[] { R.id.text1 };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
}
我的列表视图 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="326dp" >
</ListView>
</LinearLayout>
我不明白这一点,因为我有一个列表视图,其中 id 是列表?