问题描述
我有一个回收器视图 listadapter(来自 androidx)
我知道不应再将 notifyDataSetChanged() 与 ListAdaper 一起使用,但我处于一种必要的情况下(应在不更改提交列表的情况下调用 onBindViewHolder())
问题是当我像这样调用 notifyDataSetChanged() 时出现编译错误:
binding.episodesRv.adapter.notifyDataSetChanged()
编译错误:
Smart cast to '({Adapter<(androidx.recyclerview.widget.RecyclerView.ViewHolder..
androidx.recyclerview.widget.RecyclerView.ViewHolder?)> & Episodelistadapter}..
Episodelistadapter)' is impossible,because 'bd.episodesRv.adapter' is a complex expression
适配器:
class Episodelistadapter(
val context: Context,var epiId: StateFlow<Long>,val selectEpisode: (episode: Episode) -> Unit,val delete: (episode: Episode) -> Unit,) : listadapter<Episode,EpisodeViewHolder>(EPISODE_COMParaTOR) {
....
解决方法
Artem Chernousov 在上述评论中修复的问题。再次感谢。