onListItemClick を使用するために、メインのアクティビティを「ListActivity」(以前はアクティビティに拡張されていました) に拡張しようとしていますが、logcat から「あなたのコンテンツには、id 属性が 'android.r.id.list である ListView が必要です。 」。(私は ListView を作成するために SQLite を使用しています)。
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 which id attribute is android.R.id.list、または: RuntimeException: Your content must have a ListView That id attribute is 'android.R.id.list'、およびその他の質問しかし、私にはうまくいきません。ここで何が起こっているのですか?
本当に助けていただければ幸いです