1

アクティビティ内の2つの異なるListViewを取得して、データベースコンテンツonCreateを入力しようとしています。コードを追加してから、タイトルに記載されているエラーに迫られています。

なぜこれが起こっているのか分かりません。

コードは次のとおりです。

    currentList = (ListView)findViewById(R.id.list_current_day);
    cursor = datasource.fetchCurrentLogs(dayExerciseDataID);
    to = new int[] { R.id.listitem_log_reps, R.id.listitem_log_weight };
    dataAdapterCurrent = new SimpleCursorAdapter(this, R.layout.listitem_log, cursor, columns, to, 0);
    currentList.setAdapter(dataAdapterCurrent);

    previousList = (ListView)findViewById(R.id.list_previous_day);
    cursor = datasource.fetchPreviousLogs(dayExerciseDataID);
    to = new int[] { R.id.listitem_log_reps, R.id.listitem_log_weight };
    dataAdapterPrevious = new SimpleCursorAdapter(this, R.layout.listitem_log, cursor, columns, to, 0);
    previousList.setAdapter(dataAdapterPrevious);

データベースの構造と機能は次のとおりです。

public Cursor fetchCurrentLogs(long dayExerciseDataID) {
    // where day = today
    Cursor cursor = database.rawQuery("select " + MySQLiteHelper.COLUMN_ID + "," + MySQLiteHelper.COLUMN_REPS + ", " + MySQLiteHelper.COLUMN_WEIGHT + " " +
            "from " + MySQLiteHelper.TABLE_LOGS + " " +
            "where " + MySQLiteHelper.COLUMN_ID_DAY_EXERCISE + " = '" + dayExerciseDataID + "'", null);
    if (cursor != null) { cursor.moveToFirst(); }
    return cursor;
}

public Cursor fetchPreviousLogs(long dayExerciseDataID) {
    // where day = closest day from today
    Cursor cursor = database.rawQuery("select " + MySQLiteHelper.COLUMN_ID + "," + MySQLiteHelper.COLUMN_REPS + ", " + MySQLiteHelper.COLUMN_WEIGHT + " " +
            "from " + MySQLiteHelper.TABLE_LOGS + " " +
            "where " + MySQLiteHelper.COLUMN_ID_DAY_EXERCISE + " = '" + dayExerciseDataID + "'", null);
    if (cursor != null) { cursor.moveToFirst(); }
    return cursor;
}

    database.execSQL("create table " + TABLE_LOGS + " (" 
            + COLUMN_ID + " integer primary key autoincrement," 
            + COLUMN_ID_DAY_EXERCISE + " integer not null,"
            + COLUMN_REPS + " integer not null,"
            + COLUMN_WEIGHT + " real not null,"
            + COLUMN_1RM + " real not null,"
            + COLUMN_DATE + " integer not null"
            + ")");

誰かがなぜこれが起こっているのかを明らかにすることができますか?重要なコードを見逃した場合はお知らせください。質問を更新します。

4

2 に答える 2

2

cursor両方のリストに異なるインスタンスを使用してみてください。

currentList = (ListView)findViewById(R.id.list_current_day);
cursor1 = datasource.fetchCurrentLogs(dayExerciseDataID);

previousList = (ListView)findViewById(R.id.list_previous_day);
cursor2 = datasource.fetchPreviousLogs(dayExerciseDataID);
于 2013-01-27T04:55:48.110 に答える
0

SimpleCursorAdapterをこのように使用する必要があります

dataAdapterPrevious = new SimpleCursorAdapter(this, R.layout.listitem_log, cursor, columns, to);

これの代わりに

 dataAdapterPrevious = new SimpleCursorAdapter(this, R.layout.listitem_log, cursor, columns, to, 0);
于 2013-01-27T04:56:35.877 に答える