我只需要1个表的数据库。保持姓名和分数以及姓名是主要关键。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scoreboard);
SQLiteDatabase db = openOrCreateDatabase("scores", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS scores(_id VARCHAR PRIMARY KEY,score INTEGER);");
db.execSQL("INSERT INTO scores (_id, score) VALUES ('DARR',99);");
Cursor c=db.rawQuery("SELECT * FROM scores;",null);
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Player: "+c.getString(0)+"\n");
buffer.append("Score: "+c.getInt(1)+"\n");
}
String result = buffer.toString();
TextView scoreRes = (TextView) findViewById(R.id.textViewScoreResult);
scoreRes.setText(result);
}
答案 0 :(得分:-1)
我想,SharedPreferences可以满足您的需求。将名称用作'键'得分为'值'到SharedPreferences。
有关详细信息,请参阅http://developer.android.com/training/basics/data-storage/shared-preferences.html
除非应用确实需要,否则不要使用SQLite数据库。