CheckOrderExists 2 value add 1.recipe_id 2.qty + button increase qty not update.Addcart if condition not working else condition working.I want to update the qty of product when adding a product.update qty sqlite not show
public void Addcart(String category_name, long recipe_id, String recipe_title, String recipe_time, String recipe_image, String recipe_description, String video_url, String video_id, String content_type, String featured, String tags, long total_views, String _stringVal) {
try {
if (!CheckOrderExists(recipe_id).equalsIgnoreCase("0")) {
UpdateOrderData(recipe_id, _stringVal);
Toast.makeText(mContext, "Hello World", Toast.LENGTH_SHORT).show();
} else {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_CAT_NAME, category_name);
values.put(KEY_RECIPE_ID, recipe_id);
values.put(KEY_RECIPE_TITLE, recipe_title);
values.put(KEY_RECIPE_TIME, recipe_time);
values.put(KEY_RECIPE_IMAGE, recipe_image);
values.put(KEY_RECIPE_DESCRIPTION, recipe_description);
values.put(KEY_VIDEO_URL, video_url);
values.put(KEY_VIDEO_ID, video_id);
values.put(KEY_CONTENT_TYPE, content_type);
values.put(KEY_FEATURED, featured);
values.put(KEY_TAGS, tags);
values.put(KEY_TOTAL_VIEWS, total_views);
values.put(KEY_QTY, _stringVal);
// Inserting Row
db.insert(TABLE_ADDCART, null, values);
db.close(); // Closing database connection
}
} catch (Exception e) {
}
}
CheckOrderExists ZERO IS DELECTE table
public String CheckOrderExists( long recipe_id) {
String _stringVal = "0";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_ADDCART + " WHERE " + KEY_RECIPE_ID+ " = ?", new String[]{String.valueOf(recipe_id)});
if (cursor.moveToFirst()) {
_stringVal = cursor.getString(cursor.getColumnIndexOrThrow(KEY_QTY));
if (_stringVal.equals("0")) {
db.execSQL("DELETE FROM " + TABLE_ADDCART + " WHERE " + KEY_RECIPE_ID+" = ?", new String[]{String.valueOf(recipe_id)});
}
}
cursor.close();
db.close();
return _stringVal;
}
UPDATEORDER
public void UpdateOrderData(long recipe_id,String _stringVal) {
SQLiteDatabase db = this.getWritableDatabase();
if (_stringVal.equals("0")) {
DeleteOrderData(recipe_id);
} else {
ContentValues values = new ContentValues();
values.put(KEY_QTY, _stringVal);
db.update(TABLE_ADDCART, values, recipe_id + " = ?" , new String[]{String.valueOf(recipe_id)});
}
db.close();
}
I want when user click “add to cart” button then the quantity will be updated. But quantity is updated after I click the button twice.
@dda not qty update bro how to fix bro