Radio group setOnCheckedChangeListener that can work with selected radio as well

StackOverflow https://stackoverflow.com/questions/19810645

  •  04-07-2022
  •  | 
  •  

Вопрос

I am using .setOnCheckedChangeListener to check a change on Radio group with three buttons. as per name it will detect if a change in radio buttons is detected. Hence clicking on the already selected item wont invoke anything.

is there any alternative that will work even for the selected radio , ignoring that it is already selected

Это было полезно?

Решение

You question is a bit confusing. But as far as I understood, onCheckedChanged fires automatically when your activity is loaded first time provided that you have set listener in onCreate method.

You can implement on onClick but then you have to take care of both events. As onClick will fire first and then onCheckedChange will fire. And in OnCheckedChange you can detect whether the Radio button changed or not by using a temporary variable.

Hope this answers your question.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top