lundi 6 juillet 2015

Insert 2 rows to sqlite when using SQLiteOpenHelper onCreate() method

Code for creating the Database:

private static final String DB_CREATE =
                            "CREATE TABLE " + TABLE_NAME + "(" +
                                    COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                                    COLUMN_ITEM +" TEXT NOT NULL " +
                            ");";

I'm using the following code but it only inserts the last value (Swipe me to delete) but not the first (Click me to edit) , so how should I proceed to insert 2 rows?

@Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(DB_CREATE);

    ContentValues contentValues = new ContentValues();

    contentValues.put(COLUMN_ITEM, "Click me to edit");
    contentValues.put(COLUMN_ITEM, "Swipe me to delete");

    database.insert(
            TABLE_NAME,
            null,
            contentValues
    );
}

Find out how to solve it so I'm leaving the answer below but if anyone knows how to use ContentValues to insert more than 1 row I would appreciate the answer.

thanks!

Aucun commentaire:

Enregistrer un commentaire