notifyDataSetChanged()而无需刷新用户界面? [英] notifyDataSetChanged() without refreshing the UI?

查看:129
本文介绍了notifyDataSetChanged()而无需刷新用户界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来调用 notifyDataSetChanged()上,而无需刷新列表或干扰UI自定义适配器?

Is there a way to call notifyDataSetChanged() on a custom adapter without refreshing the list or disturbing the UI?

我有一个的ListView 与它后面的自定义适配器,使用客户的对象列表作为它的数据集。当客人标志着他的出勤通过点击他的名字,蜱应该旁边的客人的名字在UI中出现。这是我能做到的,但是当我打电话 notifyDataSetChanged(),名称列表推一路顶端,presumably,因为列表中的刷新。

I have a ListView with a custom Adapter behind it, using a List of Guest objects as its dataset. When a Guest marks his attendance by tapping on his name, a tick is supposed to appear next to the guest's name in the UI. This I can do, but when I call notifyDataSetChanged(), the list of names is pushed all the way to the top, presumably because the list "refreshes".

如果我的没有的通话 notifyDataSetChanged(),但是,当我滚过更新的条目并再次往回滚动刻度消失。这是由于视图的ListView的回收按照我的理解,但它肯定不会让我的工作变得更容易。

If I don't call notifyDataSetChanged(), however, the tick disappears when I scroll past the updated entry and scroll back again. This is due to the ListView's "recycling" of Views as I understand, but it sure doesn't make my job any easier.

如何将一个呼叫 notifyDataSetChanged() 没有使得整个的ListView 刷新自己?

How would one call notifyDataSetChanged() without making the entire ListView refresh itself?

推荐答案

最好能有一个布尔型字段在你的客户类别:为present。 每当用户点击列表项就可以得到所选择使用的项目adapter.getItemAtPosition()。 更新值是present为true。并显示刻度线。

Better to have one boolean field in your Guest Class :isPresent. whenever user taps on list item you can get the selected item using adapter.getItemAtPosition(). update the value isPresent to true. and make show the tick mark.

在你的适配器类。检查是present值。如果它被标记为true,则显示的刻度标记否则隐藏它。

In your adapter class. check for isPresent value. If it is marked to true then show the tick mark else hide it.

这是如何可以实现两个。显示刻度标记列表项上点击,如果您滚动列表视图,回到同一个项目,你对勾标记显示/隐藏将由适配器被照顾。

This is how you can achieve the both. Show Tick Mark on ListItem click and if you scroll the listview and come back to the same item you tickmark show/hide will be taken care by Adapter.

这篇关于notifyDataSetChanged()而无需刷新用户界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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