我正在尝试将我的主 Activity 扩展到“ListActivity”(以前扩展到:Activity)以使用 onListItemClick,但是 logcat 向我发送“您的内容必须有一个 id 属性为 'android.r.id.list 的 ListView '”。(我使用 SQLite 来填充 ListView)。
mi xml是:
<ListView
android:id="@+id/list" // to "@id/android:list" or other styles (but nothing works)
android:layout_width="fill_parent"
android:layout_height="fill_parent"/> // or closing with </ListView>
这是 ListView 的完整 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:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /></LinearLayout>
我处理 ListView 的主要类:
public class lay_main extends ListActivity{
public ListView list;
private DBHelper myAdap;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay_main);
collectXML();
setupDataBase();
setupAdapter();
}
private void collectXML()
{
list = (ListView)findViewById(R.id.list);
}
private void setupDataBase() {
myAdap = new DBHelper(getApplicationContext(), "courses", null, 1);
myAdap.insertCourses();
}
private void setupAdapter()
{
if(myAdap.getCourses()!=null)
{
cAdapter adapter = new cAdapter(this, R.layout.list_courses, myAdap.getCourses());
list.setAdapter(adapter);
}
}}
我读了 Android: Your content must have a ListView its id attribute is android.R.id.list,或者:RuntimeException: Your content must have a ListView which id attribute is 'android.R.id.list',以及其他问题,但不适合我,这是怎么回事?
真的很感谢你的帮助