Reputation: 1457
I have Fragment
A, B in the application.I have set Recyclerview
on Fragment A using API call.I have one method deleteEntry()
in Fragment B, due to which one item gets deleted from API data and I come to Fragment A after deleting the item.
This is the code after API call deleteEntry
to move to Fragment A
CurrentStatus status=new CurrentStatus();
Busy table=new Busy();
tx=fm.beginTransaction();
tx.replace(R.id.frame,new ChooseTab());
tx.detach(status);
tx.attach(status);
tx.detach(table);
tx.attach(table);
tx.commit();
But After I go to Fragment A the RecyclerView item is still visible even though the API calls again to display modified API data while replacing the Fragment.I need to manually again call the same API to refresh and then Item is gone.
How to resolve this?
Upvotes: 0
Views: 533
Reputation: 455
You need to delete the entry from the list you have passed to the adapter of the recyclerView and then call notify on the adapter like this -
list.remove(position); // to remove the item from the list
recyclerAdapter.notifyItemRemoved(position); // to notify the adapter
where position is the index of the item in the list to be removed. After this, the item will be removed from the recyclerView and no longer visible.
Upvotes: 1