切换开关状态,没有动画 [英] Change Switch state without animation
本文介绍了切换开关状态,没有动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Android项目中,我有一个的ListView
含行 SwitchCompat
项目(应用程序兼容性的开关
部件)。
In my Android project, I have a ListView
with rows containing SwitchCompat
items (AppCompat for Switch
widget).
当我滚动到列表和 getView(...)
MyAdapter
的方法被调用时我的问题以回收
视图。我重新定义了正确的切换
状态,但动画是可见的。
My problem occurs when I scroll into the list and getView(...)
method of MyAdapter
is invoked with a recycled
view. I redefine the correct Switch
state but the animation is visible.
有是prevent的溶液在此情况下,动画?
There is a solution to prevent the animation in this case?
推荐答案
我终于找到了一个解决方案,但似乎没有真正干净的:
I finally found a solution but seems not really clean:
ViewGroup viewGroup = (ViewGroup) view; // the recycled view
viewGroup.removeView(switch);
switch.setChecked(states[index]);
viewGroup.addView(switch);
如果一个更好的解决方案存在,请分享。
If a better solution exists, please share it.
这篇关于切换开关状态,没有动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文