Change Switch state without animation

alex picture alex · Nov 26, 2014 · Viewed 11.4k times · Source

In my Android project, I have a ListView with rows containing SwitchCompat items (AppCompat for Switch widget).

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.

There is a solution to prevent the animation in this case?

enter image description here

Answer

Lin picture Lin · Oct 8, 2015

Call jumpDrawablesToCurrentState() to skip the animation

switchCompat.setChecked(true);
switchCompat.jumpDrawablesToCurrentState();