notifyDataSetChanged vs setAdapter

后端 未结 2 831
暗喜
暗喜 2020-12-31 10:55

I know that it is more efficient to use notifyDataSetChanged, when I want adapter to show updated data. However, due to my design I am thinkig about resetting adapter each t

2条回答
  •  孤城傲影
    2020-12-31 11:08

    due to my design

    You should think about a change of design.

    How much cost ( in terms of execution time) such decision will add compared to using notifidatasetChanged?

    I don't like talking about "how much memory", "memory leaks" etc. but please, imagine that situation as "normal person".

    You can image your goal with a building new house. You once builded house. Everything is ok but later, you want some change! So you're going to make some changes for example change colors, replace windows with new ones, join to house some shelter etc. and what you'll do?

    You'll demolish the house? Or you'll make only changes?

    I think that answer you already know. Why you don't want to demolish the house but only make changes?

    • It'll cost too much to build new house (if you're not Bill Gates)
    • It's waste of time (changes will be made faster and they cost less)

    Same is with destroying and assigning new adapter. It's waste of time, maximal inefficient and "not comfortable at least for me".

    Make changes in adapter (like add new items, update old, change row colors etc.) is much more efficient, clean and faster. API already provides you method how you can achieve it.

    I think your idea of design is not correct and efficient and you should review what you'll do finally. Try to think about man. Hope this answer will make things more clear for you.

提交回复
热议问题