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.

  1. override getitemid(int position) , return item's id.
  2. in recycleradapter's contructor, add line:

    sethadstableids(true); 
  3. just use notifydatasetchanged() in swapdata method after you've switched lists.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -