我有启动 ListActivity 的按钮,但每次单击它时,应用程序都会崩溃并出现以下 LogCat 错误:
01-10 13:12:51.327: E/AndroidRuntime(2970): FATAL EXCEPTION: main
01-10 13:12:51.327: E/AndroidRuntime(2970): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app/com.app.Settings}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
这是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
android:padding="15dip" >
<ListView
android:id="@+id/listViewSettings"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
这是Java代码:
import java.util.ArrayList;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class Settings extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
ArrayList<String> listItems=new ArrayList<String>();
listItems.add("foo");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
listItems);
setListAdapter(adapter);
}
}
我已经尝试将列表 ID 更改为,list
但如果这样做,我会收到以下错误:
If I do this I get the following error: `Error: No resource found that matches the given name (at 'id' with value '@id/list').`