I have a group of radio stations for which I implemented onCheckedChanged , which looks like this:
RadioGroup mRadioGroup = (RadioGroup) findViewById(R.id.radio_grp); mRadioGroup.setOnCheckedChangeListener(this);
My activity implements OnCheckedChangeListener ,
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (group.getId()) { case R.id.radio_grp: if (my condition is true) { Log.d(TAG, "want to change the radio group checked button if code reaches here."); } else { Log.d(TAG, "do not want to change the radio group checked button if code reaches here."); } break; default: break; } }
Now, when the user clicks on the switch, he runs the code inside onCheckedChanged, and also checks the switch that the user clicked. But I want to check if my condition is really true, then only it should change the choice of the switch and not change if the condition is false.
can anyone suggest what i should do?
Thanks!
PS: I also canβt think what I should write in the βSubjectβ of this question, so if someone can complete the topic, edit it.
PPS: I tried to reset the state of the radio group using group.check(R.id.last_selected_id); but this will throw a StackoverFlow exception as the code gets stuck in an infinite loop.
mudit source share