是否将Mutablelist转变为.submitlist()的新列表? - 循环系统,litchadapter

发布于 2025-01-22 07:38:13 字数 456 浏览 3 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文