0

ここのAndroid初心者、リストビューにアイテムを入力するのに問題があります。データベースエントリ値の1つをいつでも表示できますが、リスト行ごとに2つのアイテムが必要です。これがリストビューにデータを入力するための私のクラスです。KEY_TITLEとKEY_BODYの値をリストビューに入れたいです。理想的には、KEY_BODYをリストビューのサブアイテムにしたいのですが、APIを読んだ後でも、実装方法がわからない2アイテムのリストビューが必要になる場合があると思います。

@SuppressWarnings("deprecation")
private void fillData() {
Cursor moviesCursor = mDbHelper.fetchAllMovies();
startManagingCursor(moviesCursor);

String[] from = new String[]{
    MyMoviesDBAdapter.KEY_ROWID,
    MyMoviesDBAdapter.KEY_BODY,
    MyMoviesDBAdapter.KEY_TITLE
};

int[] to = new int[] {
    R.id.text3,
    R.id.text2,
    R.id.text1
};

ListAdapter movies = new SimpleCursorAdapter(this, R.layout.listtextview,
                        moviesCursor, from , to);
moviesCursor.moveToNext();
setListAdapter(movies);
}

これが私のXMLレイアウトです

<LinearLayout >
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dip"
android:textColor="#a4a4a4"
android:textSize="10sp"
 />
<TextView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dip"
android:textColor="#ffffff"
android:textSize="24sp"
 />
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dip"
android:textColor="#a4a4a4"
android:textSize="15sp"
 />
</LinearLayout>
4

2 に答える 2

0

あなたは逃したBaseColumns._ID

String[] from = new String[]{
    MyMoviesDBAdapter.KEY_ROWID,
    MyMoviesDBAdapter.KEY_BODY,
    MyMoviesDBAdapter.KEY_TITLE,BaseColumns._ID
};
于 2013-01-29T07:06:13.150 に答える
0

問題は私の XML レイアウトにありました。親の「線形レイアウト」で詳細を指定するのを怠ったため、実行時例外が発生しました。これが誰かに役立つことを願っています

于 2013-01-29T23:16:09.437 に答える