Android radio after check check

friends. I have a very silly problem with a radio group. However, I cannot find a solution.

I will try to describe how to reproduce my problem: I have a radio group and two buttons inside. I choose one of them, say the 1st. Then I clear the selection by calling radioGroup.clearCheck () After I try to select the 1st button, but don't check it. If I check 2nd, it is checked normally. If I check 1st after checking 2nd, it also works fine.

It may seem crazy, but I can’t fix it. Please help me, thanks in advance.

I use

@Override protected void init() { View view = View .inflate(getContext(), R.layout.wo_task_yn_result, null); performed = (RadioButton) view.findViewById(R.id.yn_yes); notPerformed = (RadioButton) view.findViewById(R.id.yn_no); radioGroup = (RadioGroup) view.findViewById(R.id.yn_options); performed.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { Log.d(YES, "verify"); if (isChecked) { Log.d(YES, "checked"); result = YES; } } }); notPerformed.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { Log.d(NO, "verify"); if (isChecked) { Log.d(NO, "checked"); result = NO; } } }); addView(view); } 

To create buttons and

 @Override public void clear() { radioGroup.clearCheck(); result = ""; } 

to clean them

+7
source share
3 answers

I had the same problem. Failed to select the first radioButton in the group, but may select the other two. And after choosing the second radioButton, I could choose the first. I resolved this by making one radioGroup.clearCheck () instead of a separate radioButtonA.setChecked (false)

+16
source

Use OnCheckedChangeListener and use the setSelected(true) or setChecked(true) method.

0
source

If you want to uncheck the box using the switch, try this method:

 @Override public void clear() { performed.setChecked(false); nonperformed.setChecked(false); } 
0
source

All Articles