Android 将 listview 视图存储到 ArrayList 中

发布于 2024-11-17 17:28:36 字数 505 浏览 1 评论 0原文

我遇到 ListView 重新渲染和更改列表视图中的值的问题。每个单元格都有带有已设置数值的交互式元素,不幸的是,一旦离开屏幕,这些数字就会看似随机地重新渲染!

我后来发现 Listview 需要一个扩展视图类来允许存储该位置的值。

我需要传递多个值,到目前为止,我看到的所有示例仅显示一种方法,每个单元格一个值(参考 http://commonsware.com/Android/excerpt.pdf),我正在寻求有关如何存储应用程序值的帮助。

我有一个“总”计数,以及一个单独的计数,我可以通过列表视图单元格中的按钮增加和减少其值。我需要将这些单独的总计和值存储在视图中的该位置内。我想我会有一个只包含这些值的方法/构造函数,但在这种语法中似乎是超级的。将不允许这种覆盖。

洞察力赞赏。如果没有代码还不清楚,请告诉我。但如果您已经熟悉这个问题以及解决它的最通用的方法,那就太好了。

I have the problem of the ListView re-rendering and changing the values within my list view views. Each cell has interactive elements with numerical values that are set, unfortunately once off screen these numbers are re-rendered seemingly at random!

I've since discovered that Listview needs to have an extended view class that allows the values at that position to be stored.

I need to pass several values, so far all the examples I have seen only show one method with one values per cell (referring to http://commonsware.com/Android/excerpt.pdf), I am seeking assistance on how to store the values for my application.

I have a "total" count , and a separate count that I can increase and decrease the value of, via buttons within the listview cell. I need to store these individual totals and values within that position in the View. I supposed I would have a method/constructor that simply includes those values, but in this syntax is seems the super. will not allow this override.

Insight Appreciated. If this wasn't clear without code, sure just let me know. But if you are already familiar with this problem and the most generic way to tackle it, that would be great too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔书几行 2024-11-24 17:28:36

Listview 回收其视图,因此如果您不使用适合您目的的自定义适配器显式存储显示的值,则可能会出错。每当您将列表视图中的视图滚动出屏幕时,它都会丢弃其中的所有值,并将其与新数据粘贴到顶部。

因此,您可能需要一个自定义适配器来存储您想要显示的数字;这是一个更好地理解它的好地方:http://developer .android.com/videos/index.html#v=wDBM6wVEO70

Listview recycles its views, so if you don't store the values you are displaying explicitly using a custom adapter fit for your purposes, that is probably were it goes wrong. Whenever you scroll a view in the listview out of the screen, it throws away all the values in there, and pastes it on top with new data.

So what you probably need is a custom adapter storing the numbers you want to display; here is a good place to start off from in understanding it better: http://developer.android.com/videos/index.html#v=wDBM6wVEO70

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文