Heres is update method is DatabaseHelper
public void updateFavorite(String p_name, String n_fav, SQLiteDatabase sqLiteDatabase){
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_FAVORITE,n_fav);
String updateQry = KEY_FAVORITE + " LIKE ?";
String string[] = {p_name};
sqLiteDatabase.update(TABLE_NAME,contentValues,updateQry,string);
sqLiteDatabase.close();
}
And here is my code in activity
s_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String fav;
fav = uEdName.getText().toString();
databaseHelper = new DatabaseAccess(ReceiveDataActivity.this);
sqLiteDatabase = databaseHelper.getWritableDatabase();
databaseHelper.updateFavorite(KEY_FAVORITE,fav,sqLiteDatabase);
Toast.makeText(getApplicationContext(),"set 0",Toast.LENGTH_LONG).show();
//finish();
}
});
The database doesn't update the database.
You're passing KEY_FAVORITE
as p_name
, so (if KEY_FAVORITE
is "FAVORITE"
) your query ends up being
FAVORITE LIKE FAVORITE
which probably isn't what you meant. To fix it, correct the parameters to your updateFavorite
call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.