Aron Aron - 6 months ago 209
Android Question

Delete item from SQLite and then RecyclerView

my sqlite delete code

public void deleteItem(int position) {
SQLiteDatabase db = getWritableDatabase();
db.delete(TABLE_PLACE, ID + "=?" + position , null);
}








recyclerview

@Override
public void onItemRemoved(int position) {
places.remove(position);
notifyItemRemoved(position);
notifyDataSetChanged();
}


How can i delete any row from
SQLite
database and then delete it from
RecyclerView
too

Answer

Can you try this way :

public void deleteItem(int position) {
    SQLiteDatabase db = getWritableDatabase(); 
    db.delete(TABLE_PLACE, ID + "=?" + position , null);
    //you can try theese following 2 lines to delete
    db.execSQL("DELETE FROM " + TABLE_NAME+ " WHERE "+COlUMN_NAME+"='"+value+"'");
    db.close();
    places.remove(position);
    adapter.notifyDataSetChanged();
    //or like this
    adapter.notifyItemRemoved(position);
    }