java - Android recyclerview: more efficient notifydatasetchanged or notifydatarangeremoved then notifydatarangeinserted? -
i have recyclerview number of elements changes time. might have 5 items, 7, 70. more efficient way of changing out entire dataset:
1) calling clear(), adding new dataset calling notifydatasetchanged?
2) calling clear(), calling notifyitemrangeremoved, adding new dataset , calling notifyitemrangeinserted?
public void swapdata(arraylist<datatype>() newdata) { int oldsize = recyclerlist.size(); recyclerlist.clear(); if (oldsize > 0) { notifyitemrangeremoved(0, oldsize); } ... }
the easiest way involves few steps, works if items have proper ids.
- override
getitemid(int position)
, return item's id. in recycleradapter's contructor, add line:
sethadstableids(true);
just use
notifydatasetchanged()
in swapdata method after you've switched lists.
Comments
Post a Comment