I've tried the following method to do the task but it isn't working but doesn't show any errors at all. This is the comparing part:
Cursor res = myDb.showKharcha();
final String selected= parent.getItemAtPosition(position).toString();
while(res.moveToNext()) {
if(selected == res.getString(1)) {
int num = Integer.parseInt(editText.getText().toString());
num = num + Integer.parseInt(res.getString(2));
boolean isUpdated = myDb.updateData(res.getString(0),selected,num);
if (isUpdated == true) {
Toast.makeText(add_trans.this,"Kharcha updated to "+ selected,Toast.LENGTH_LONG).show();
} else {
Toast.makeText(add_trans.this, "Kharcha not added", Toast.LENGTH_LONG).show();
}
This is the showKharcha
function in DatabaseHelper class:
public Cursor showKharcha(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor tyt = db.rawQuery("select * from " + TABLE_NAME,null);
return tyt;
}
The database Update code is:
public boolean updateData(String ID, String KharchaType, Integer Kharcha){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1,ID);
contentValues.put(COL_2,KharchaType);
contentValues.put(COL_3,Kharcha);
db.update(TABLE_NAME,contentValues, "ID = ?",new String[] { ID });
return true;
}