android radiobutton check after clearing check issue
Asked Answered
S

3

8

friends. I'm having a really silly problem with radiogroup. Yet I'm unable to find solution.

I will try to describe how to reproduce my problem: I have radiobutton group and two buttons inside. I select one of them, lets say 1st one. Then I'm clearing selection by calling radioGroup.clearCheck() After I'm trying to select 1st button, but its not checking. If I check 2nd, it checks normally. If I check 1st after checking 2nd it also works normally.

This may sound crazy, yet 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 = "";
}

for clearing them

Suber answered 5/4, 2012 at 14:25 Comment(5)
it would be best if you show thde code for the buttonsNole
Ok, I've updated my questions. Hope this code is enough.Suber
post it for the SO community.Nole
Well not to humble, when i said, I've found solution, it just stupid bug in my code. It was connected with my tryings of reusing fragment and it's a little bit to complex to post it here.Suber
@Orest, I am also facing kind of similar issue at my end, can you please by some way help me by explaining what was problem in your case? Thanks.Allayne
H
18

I had the same problem. Was unable to select the first radioButton in the group, but could select the other two. And after selecting the second radioButton, I could select the first one as well. I resolved it by doing a single radioGroup.clearCheck() instead of individual radioButtonA.setChecked(false)

Hootman answered 26/6, 2013 at 7:45 Comment(2)
I used radioGroup.removeAllViews() to remove all view. I also think that all checked item will be clear. But it's not work. But radioGroup.clearCheck() works like a charm. Thanks alotPitzer
It's work for me but small issue is occur i change BG(set selector) of radio button on button check when i set radioGroup.clearCheck() BG not set as per my selector can yo please tell me what wrong with this?Unbearable
D
0

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

Dhole answered 5/4, 2012 at 14:32 Comment(0)
C
0

if u want to uncheck radio button try this method:

@Override
public void clear() {

performed.setChecked(false);

nonperformed.setChecked(false);

}
Coseismal answered 5/4, 2012 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.