What's better? notifyDataSetChanged or notifyItemChanged in loop?

后端 未结 3 688
耶瑟儿~
耶瑟儿~ 2020-11-29 00:42

So I have an activity with RecyclerView and I want to change TextView of every item in the RecyclerView by pressing button that has

3条回答
  •  抹茶落季
    2020-11-29 01:07

    I would definitely call notifyDataSetChanged() if all of the data items ar no longer valid. When you call notifyItemChanged(mPos), it is equivalent to a call to notifyItemRangeChanged(mPos, 1), and every time it is called, requestLayout() is also called. On the other hand, when you call notifyDataSetChanged() or notifyItemRangeChanged(0, mList.size()), there is only one call to requestLayout().

    Your question should now be, what is better, a call to notifyDataSetChanged() or notifyItemRangeChanged(0, mList.size())? For that one I don't have an answer.

提交回复
热议问题