Android 如何保存列表视图的状态
是否有我可以使用的 listviewObject.saveViewStates(view)
函数?我有列表视图,我有其他带有自定义适配器的列表视图,但这些都没有保存视图的状态。这些列表视图中有很多动态生成的内容,因此,当然,当该行超出视图时,数据会被重置。
我理解视图持有者背后的概念,但我很难追溯地将我的列表视图与它们相匹配。 (nullexceptions,非法状态异常)
由于保存视图的常见方法是传递视图,因此列表视图有一个简单地接受视图作为变量的内置函数不是有意义吗?我知道列表视图是在考虑到有限内存的情况下创建的,与 webview 相比,没有办法保存内置状态似乎是疏忽了 - webview 也是在考虑到有限内存的情况下构建的 - 用户可以强制启用/禁用缓存,进行自己的内存管理等。
洞察力值得赞赏
Is there a listviewObject.saveViewStates(view)
function I can use? I have listviews, I have other listviews with custom adapters, but neither of these save states of the view. There is a lot of dynamically generated content in these listviews, so of course, when it that row goes outside of the view, the data is reset.
I understand the concept behind a viewholder, yet I am having great difficulty retroactively fitting my listviews with them. (nullexceptions, illegalstateexceptions)
Since the common way of holding the view is to pass the view, wouldn't it make sense that the listview had a built in function that simply accepted the view as a variable? I understand that the listview was created with limited memory in mind, it just seems negligent that there wouldn't be a way to save the states built in, in contrast to the webview - which is also built with limited memory in mind - the user can force enable/disable caching, do their own memory management etc.
Insight appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
列表的整体思想是它是动态的并且可能很长 - 因此有很多不可见的行。因此,适配器方法的目标是仅保留屏幕上可见的尽可能多的视图,并通过运行 getView() 用数据填充它们 - 如果不再需要,它应该重用视图。
因此,当您将其纳入帐户时,它变得非常简单,应该保存/重新加载背后的数据模型(存储在适配器中),并且在重新加载列表并填充模型中的数据时应该重建列表视图。
这更符合列表的概念。
The whole idea of the list is that it is dynamic and can be potentially long - so have lots of rows which are invisible. Therefore the aim of the adapter approach is to only keep as many views as visible on screen and fill them with data by running getView() - which should reuse views if no longer needed.
So when you take that in the account, it becomes pretty straightforward, that it's the data model behind (stored in adapter) that should get saved/reloaded and the list views should be rebuild when list is reloaded and filled with the data from the model.
This is more in-line with the list concept.