在列表视图排布置的动态变化会影响其他行过视图、动态、列表

2023-09-06 23:22:57 作者:劳资,虐遍全球

我使用ListView和有每个列表元素上的几个按钮。

I am using ListView and there are several buttons on each list element.

当被点击一排按钮,该按钮就会消失。当点击这是确定的点击按钮消失。问题是一些其他列表元素按钮没了。

when a button on a row is clicked that button should disappear. the clicked button disappears when clicked that's ok. the problem is some of the other list elements buttons are gone too.

例如,当我点击第一个元素按钮,它会影响在6日,11日的按钮,16元了。同时7元素按钮会影响第2,第12,第17元素。

for example, when I click 1st elements button it affects the buttons in the 6th, 11th, 16th elements too. also 7th elements button affects 2nd, 12th, 17th elements.

的原因是,适配器不用于数据中的所有的元素创建的列表元素。它仅足以创建多个对象,以显示在屏幕上。如图列表中的下降时的图象,顶部元件成为最后及其值改变。所以当我在第一个元素隐藏按钮,在第8个元素(数字从图片)按钮被隐藏了。

the reason is that the adapter doesn't create list element for all the elements in the data. it only creates several objects enough to show on the screen. as shown in the picture when going down in the list, top element becomes the last and its values are changed. so when I hide button in the first element the button in the 8th element (numbers are from the picture) is hidden too.

我能避免使用创建项目的副本,并创建新项目的每一个元素可能是解决方案,但它减缓了应用程序观看如此多的行之后。

I can avoid to use copies of created items and create new item for each elements could be solution but it slows the application after viewing so many rows.

我一直在寻找小时,但找不到任何解决办法。我希望有人知道任何解决方案或至少建议我一种别样的适配器,实现什么的。

I've been looking for hours but couldn't find any solution. I hope someone knows any solution or at least suggest me a different kind of adapter, implementation or something.

推荐答案

您应该跟踪显示或隐藏的每个元素按钮状态天气。在 getView()适配器检查当前元素状态,则隐藏或显示按钮相应的方法。使用这种方法时一定要设置每个按钮状态不仅是一个应该被隐藏,所以当视图循环,视图获取新项目的状态不是旧的。

You should keep track of each element buttons state weather shown or hidden. in getView() method of the adapter check for the current element state then hide or show button accordingly. when using this method make sure to set each button state not only the one that should be hidden so when the view recycle, the view gets the new item state not the old one.