当我在Xamarin的ListView中选择一项时,选择了Twin [英] When I chose one item in ListView in Xamarin Android is choosen twin

查看:45
本文介绍了当我在Xamarin的ListView中选择一项时,选择了Twin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Xamarin的ListView中选择一项时,选择的是twins.在Xamarin.Forms中,设置了ListView的缓存策略:RetainElement 和RecycleElement.

When I chose one item in ListView in Xamarin Android is choosen twins . In Xamarin.Forms exist setting the Caching Strategy of ListView : RetainElement and RecycleElement .

С#

var listView = new ListView(ListViewCachingStrategy.RecycleElement);

XAML

<ListView CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
          ...
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>
</ListView>

如何在Xamarin Android中配置缓存?原因是我有问题,当我在ListView中选择某些项时,在ListView的另一部分中选择了两次对称.我必须做些什么来解决这个问题?说我请有人!比你!

How can I config cache in the Xamarin Android ? Cause I have are problem , when I choose some Items in the ListView it's choosen twice symmetric in another part of ListView . What I must to do to fix that ? Say me please somebody ! Than You !

推荐答案

回收的工作方式是这样的:显示列表时,假设显示了6个项目,那么您将拥有至少6个单元格实例的池.滚动时,消失的单元格实例将返回"到未使用"的实例池中.当列表视图必须显示新的单元格时,将使用此池,以便将现有实例再次用于具有其他内容的其他行.

recycling works like this: when you display your list, let's say there are 6 items displayed, then you will have a pool of at least 6 cell instances. When you scroll, the instances of the cells that disappeared "return" to the "unused" instances pool. This pool is used when the listview has to display a new cell, so that the existing instances get used again for other lines, with other content.

请查看此答案以获取详细说明

您的问题似乎是单击单元格时单元格(视图实例)的状态发生了变化,而在重用该实例时未重置该状态.

Your issue seems to be that the cell (view instance) state changes when you click on a cell, and is not reset when reusing that instance.

您应该跟踪每个单元格内容的状态,并在获取任何单元格时对其进行分配. ViewHolder模式是管理它的好方法

You should keep a trace of the state of each cell's content and assign it when getting any cell. The ViewHolder Pattern is a good way to manage it

希望有帮助

这篇关于当我在Xamarin的ListView中选择一项时,选择了Twin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆