1

そのため、ListView に SQLite データベースのデータを数日間表示させようとしましたが、まだ解決策が見つかりません。

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" >


<Button 
    android:id="@+id/gotoEntry"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="New Entry" />

<ListView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/list" >
</ListView>

</LinearLayout>

行アイテムは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:textSize="15dp"
android:padding="15dp"
android:id="@+id/thetext"
>
</TextView>

私のカーソルアダプタは次のようになります:

public class ItemAdapter extends CursorAdapter{
private Cursor iCursor;
private Context iContext;
private final LayoutInflater iInflater;


public ItemAdapter(Context context, Cursor c) {
    super(context, c);
    iInflater=LayoutInflater.from(context);
    iContext=context;
}


@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView itemName = (TextView) view.findViewById(R.id.thetext);

    itemName.setText(cursor.getString(cursor.getColumnIndex(db_Setup.KEY_NAME)));
    }
}


@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) throws InflateException {
    final View view = iInflater.inflate(R.layout.single_item, parent, false);
    return view;
}
}

カーソルはこのメソッドで作成されています:

public static Cursor getName() {
    Cursor q = myDatabase.query(DATABASE_TABLE, new
        String[] {db_Setup.KEY_NAME}, null, null, null, null, null);
q.moveToFirst();

return q;
}

次のようにリストアクティビティでインスタンス化されます。

Cursor cursor = db_Setup.getName();

リストビューをカーソルにバインドするために、ListActivityでこれを実行しようとしています:

ItemAdapter ia = new ItemAdapter(getBaseContext(), cursor);
ia.bindView(findViewById(R.id.thetext), getApplicationContext(), cursor);

アプリを実行してもエラーはありません...この投稿の上部にあるXMLのボタンと空白(listViewなし)があります... SQLiteデータベースにすでに14のような値を入力しました値など。何も表示されないのはなぜですか?

4

1 に答える 1

0

最後の行は正しくありません。ItemAdapter を作成したら、ListActivity.setListAdapter(ia) を呼び出すだけです。詳細については、クエリ結果の表示を参照してください。

于 2012-07-15T02:40:21.127 に答える