I have a problem removing an item from my RecyclerView (which is linked to a database SQLite ). After successfully removing the data from both the database and the view, the animation is shown as deleted, but then a new element appears at the end, also with a nice animation.
When checking the database I see that the record in question is deleted.
I could solve this by instantiating a new adapter every time I delete a record, but then the animation is not displayed.
Code:
Adapter method:
public void removeItem(int position){
db = new DBAdapter(context);
db.open();
mCursorAdapter.getCursor().moveToPosition(position);
int idnota = mCursorAdapter.getCursor().getInt(0);
db.borra_nota(idnota); //it deletes the row (delete_note)
db.close();
}
Main Activity :
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
//if (direction == ItemTouchHelper.LEFT) {
listAdapter.removeItem(position);
listAdapter.notifyItemRangeChanged(position, listAdapter.getItemCount());
listAdapter.notifyItemRemoved(position);
The seedy solution (without animation) happened to be something like this:
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
sticky = (RecyclerView) findViewById(R.id.lista_notas);
linearLayoutManager = new LinearLayoutManager(MainActivity.this);
sticky.setLayoutManager(linearLayoutManager);
listAdapter = new ListAdapter(MainActivity.this);
sticky.setAdapter(listAdapter);
In which case, I would pass the removeItem
and so on within the Adapter .
Any solution so that when the record is deleted, the animation is displayed correctly and also does not create a ghost record at the end?