我有一个只包含一个值的数据库。它有两列,分别是“id”和“status”。 id = 1且status = FALSE。当我写的条件满意时,我想将我的表更新为TRUE。
System.out.println("!!!!!entered here!!!!!!!!!");
ContentValues cv = new ContentValues();
cv.put("1", "TRUE");
System.out.println("!!!!!entered here!!!!!!!!!");
db.update("main", cv, "id = 1", null);
System.out.println("??????not entered here??????");
它迫使我退出并且没有更新我的桌子。
我正在尝试检查条件,如果满足则使状态为TRUE。如果状态为FALSE,我的应用程序进入CheckScreen,如果它为TRUE,我的应用程序将不会进入该屏幕。
我也在听你解决这个案子的方法。
答案 0 :(得分:0)
您的内容值:
ContentValues cv = new ContentValues();
cv.put("1", "TRUE");
应该是
ContentValues cv = new ContentValues();
cv.put("status", "TRUE");
status是要更新的列名。
例如:
DBHelper dbHelper = new DBHelper(context);
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues updateValues = new ContentValues();
updateValues.put("status", "TRUE");
int updated = db.update(MYDATABASE_TABLE, updateValues, KEY_ID+"="+id, null);
答案 1 :(得分:0)
我找到了解决问题的方法,我使用了共享偏好设置。我的目的是在设备上保持一个最初为“假”的状态,当用户下载应用程序时,输入密码,使该状态为“true”。
我的Intro.class
SharedPreferences mSharedPrefs = getSharedPreferences("xmlFile", MODE_PRIVATE);
boolean checkValue = mSharedPrefs.getBoolean("bool", false);
if (checkValue) {
Intent intent = new Intent(Intro.this, MainScreen.class);
startActivity(intent);
} else {
Intent intent = new Intent(Intro.this, KeyCheckClass.class);
startActivity(intent);
}
}
我的KeyCheckClass.class
...
private boolean check(String str) {
// my validation algorithm
}
SharedPreferences mSharedPrefs = getSharedPreferences("xmlFile",
MODE_PRIVATE);
SharedPreferences.Editor mPrefsEditor = mSharedPrefs.edit();
mPrefsEditor.putBoolean("bool", true);
mPrefsEditor.commit();
return true;
}
在我的MainScreen.class上,我的应用程序真正开始。现在,在输入有效密码后,手机不会再次进入KeyCheckClass.class,将其传递给MainScreen.class