Reputation:
I have a piece of code in my activity like this:
for(int counter = 0; counter < markers.size(); counter++) {
sum_markers += markers.get(counter).getPrice();
}
So after I removed an item from my recyclerview I have to update my data somehow, because I have to recalculate the sum of prices (and a lot of other things).
Upvotes: 1
Views: 2195
Reputation: 34180
Use below code
public void removeItem(List< TodoItem > currentist){
list= currentist;
notifyDataSetChanged();
}
notifyDataSetChanged() : It refresh the list inside recycler view.so every time when you modified something used it and kept the current list in adapter.
If you want to refresh your fragment after you removed any item for that you have to use below code.
getSupportFragmentManager()
.beginTransaction()
.detach(contentFragment) // detach the current fragment
.attach(contentFragment) // attach with current fragment
.commit();
Hope these help you.
Upvotes: 1
Reputation: 1058
// Reload current fragment
Fragment frg = null;
frg = getSupportFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
you can take a look at this refresh recyclerview in a fragment
but if are using listview and custom adapter you can call ListAdapter.notifyDataSetChanged()
to force refresh of the list once the data has changed.
Upvotes: 1
Reputation: 3169
For Updating your UI after removing item from your list, just notify by notifyDataSetChanged(); calling this in adapter on UI thread. it will update automatically.
Upvotes: 0