public void refleshListView() {
dba = new Db(MainActivity.this);
SQLiteDatabase dbaRead = dba.getReadableDatabase();
Cursor c = dbaRead.query("user2", null, null
, null, null, null, null);
mA = new SimpleCursorAdapter(MainActivity.this, R.layout.user_info, c,
new String[]{"_id"}, new int[]{R.id._id});
lieBiao.setAdapter(mA);
}
public void onClick(View view) {
refleshListView();
String shuru = textSR.getText().toString();
String neirong = "你输入的内容是:" + shuru;
Toast.makeText(MainActivity.this, neirong, Toast.LENGTH_LONG).show();
dba = new Db(MainActivity.this);
SQLiteDatabase dbaWrite = dba.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("_id", shuru);
dbaWrite.insert("user2", null, cv);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE user2(_id INT DEFAULT 0)");
db.execSQL("CREATE TABLE user3(_id INT DEFAULT 0)");
}
写入和读取都只能使用user2,如果使用user3就会报错,说不存在table:user3报错内容如下:
PID: 7829
android.database.sqlite.SQLiteException: no such table: user3 (code 1): , while compiling: SELECT * FROM user3
慕标琳琳
相关分类