Why RecyclerView.notifyItemChanged() will create a new ViewHolder and use both the old ViewHolder and new one?

后端 未结 6 558
半阙折子戏
半阙折子戏 2020-12-18 17:57

Recently I use RecyclerView and add a custom header view (another type of item view) and try to updated it when data has changed. Something strange happens. The adapter crea

6条回答
  •  Happy的楠姐
    2020-12-18 18:24

    You can also use notifyItemChanged with a payload: https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#notifyitemchanged. It will reuse the same ViewHolder instance: "if the item is already represented by a ViewHolder and it will be rebound to the same ViewHolder"

提交回复
热议问题