I am getting strange behavior of Radio Button in Oreo 8.0.1
, Radio button is partially selected which is already discussed on Stackoverflow
here and here.
In above Image First Radio Button
is partially selected, this occurs only when we checked radio button programmatically
This is I think animation bug according to this answer and fixed with calling jumpDrawablesToCurrentState()
, but now I am getting partially unChecked
when changing the state only programmatically
first time, please look
Here First Radio Button is selected but second radio button is still partially checked.
Asked
Active
Viewed 403 times
2

Zubair Akber
- 2,760
- 13
- 30

Hussain Sherwani
- 536
- 5
- 22
1 Answers
2
Yes it looks like an animation bug, but you should refresh your layout using invalidate and requestLayout methods
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
view.invalidate();
view.requestLayout();
}

Bilal uddin
- 114
- 1
- 7
-
I think `requestLayout` adds unnecessary performance cost since layout didn't change. Why don't you explain what each method does and why should we call it? – Eugen Pechanec Apr 18 '18 at 09:57
-
@Eugen Pechane thanks, Is there any best solution to avoid such kind of issues, As I am getting this only in `Oreo 8.0.1` but this one solving my issue. – Hussain Sherwani Apr 18 '18 at 10:05
-
@Eugen Pechanec i also came across the same issue on Oreo device only and these line of code help me fix that, if you have any better solution do let me know – Bilal uddin Apr 18 '18 at 10:06
-
My guess is that `invalidate` would suffice. `invalidate` forces redraw, which should be enough because only alpha is broken. `requestLayout` forces recomputing position of the whole layout hierarchy, which is waste of CPU because the position is correct. I want you to know what you're doing. In your answers explain what your code does so other people know it as well. @HussainSherwani Don't just blindly copy-paste something without understanding. – Eugen Pechanec Apr 18 '18 at 10:30
-
@Eugen Pechanec Thanks for this, actually I am not blindly copy pasting the code, I tried this with `invalidate` only but still I was facing issue, kindly check ..`https://stackoverflow.com/a/35281876/3026578` also I already fixed this issue before this answer... Cheers – Hussain Sherwani Apr 18 '18 at 10:42
-
@HussainSherwani Thanks for that link, yes, I was expecting something like that in this answer too. The link says: `If you are not doing anything to your view that would change its size, then you do not have to call requestLayout().` so now the question is, why your case doesn't work without `requestLayout`... – Eugen Pechanec Apr 18 '18 at 10:58
-
Thanks, Actually my `Radio Button` is not in `RadioGroup`, I was handling them manually, in some situation I show `three button` in some condition I show `two` and `one` too according to my situation. Actually this is animation bug it occurred in a specific scenario only first time, second time when I repeat same scenario this will not occur, I `debugged` this too. In debugging I got `mCheked = false` for second button. but it show as partially check . look like animation bug. Cheers – Hussain Sherwani Apr 18 '18 at 11:09