是否将Mutablelist转变为.submitlist()的新列表? - 循环系统,litchadapter
我正在使用ListAdapter进行回收库,并且由于我正在使用ViewModel中的MutableList合作,因此如果我只通过了相同的MutabLeList更新,则我的RecyClerview UI不会更新列表。简单的解决方案是键入“ it.tolist()”,但我担心这需要太长创建一个全新的列表。有更好的方法吗?另外,解释“ .tolist()”的工作方式可能有助于我理解这一点。
来自:
viewModel.basicItems.observe(viewLifecycleOwner) {
recyclerAdapter.submitList(it)
}
到:
viewModel.basicItems.observe(viewLifecycleOwner) {
recyclerAdapter.submitList(it.toList())
}
I'm using a ListAdapter for my recyclerView and because I'm working with a mutableList in my viewModel, my recyclerView UI does not update the list if I just pass the same mutableList updated. The simple solution is to type 'it.toList()', but I worry this takes too long creating an completely new list. Is there a better way? Also, explaining how '.toList()' works might help me understand this.
from:
viewModel.basicItems.observe(viewLifecycleOwner) {
recyclerAdapter.submitList(it)
}
to:
viewModel.basicItems.observe(viewLifecycleOwner) {
recyclerAdapter.submitList(it.toList())
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论