I am learning android and building a rather big project. My goal is to let the user change their Email address onClick in the MainActivity, but I can't figure out how to change a value in the database.
I know it should be something along the lines:
db.update(TABLE_NAME, cv, where, value);
The problem is that the database is defined in the SQLiteHandler class, but I can't figure out how to use the same "db" in the "update" code. I keep getting "Cannot resolve method.." on the db.update.
I tried copying
SQLiteDatabase db = this.getWritableDatabase();
to my MainActivity, but at this point I'm lost.
I followed this tutorial for the registration system.
My code so far:
private static final String TABLE_NAME = "email";
btnChangemail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
db = new SQLiteHandler(getApplicationContext());
HashMap<String, String> user = db.getUserDetails();
String email1 = user.get("email");
String s1 = etChangemeil.getText().toString();
ContentValues cv = new ContentValues();
cv.put(user.get("email"), s1);
String where = (user.get("email")) ;
String[] value = { email1 };
db.update(TABLE_NAME, cv, where, value);
}
});
Best regards,
Dan
Aucun commentaire:
Enregistrer un commentaire