我的数据是从另一个activity intent过来的。
Intent intent = getIntent();
String inputName = intent.getStringExtra("content");
String inputScore = intent.getStringExtra("timeSpent");
SQLiteDatabase db = myOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();
//Retrieve the intent
values.put("name", inputName);
int intScore = Integer.parseInt(inputScore);
values.put("score", intScore);
db.insert(CustomOpenHelper.TABLE_NAME, null, values);
displayDataInTable();
——————————————————————————————
List<String> queryTable(){
List<String> player = new ArrayList<String>();
SQLiteDatabase sqLiteDatabase = myOpenHelper.getReadableDatabase();
Cursor cursor = sqLiteDatabase.query(CustomOpenHelper.TABLE_NAME,null,null,null,null,null,null);
while (cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex("name"));
int score = cursor.getInt(cursor.getColumnIndex("score"));
player.add(" --> the player " + name + " has got a score of " +score);
}
return player;
}
holdtom