0

I have some RadioButtons in a RadioGroup, and I set OnCheckedChangeListener to the RadioGroup like this:

public class RadioGroupActivity extends AppCompatActivity {

    @Bind(R.id.radio_a)
    RadioButton radioA;
    @Bind(R.id.radio_b)
    RadioButton radioB;
    @Bind(R.id.radio_c)
    RadioButton radioC;
    @Bind(R.id.radio_group)
    RadioGroup radioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radio_group);
        ButterKnife.bind(this);

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                Log.i("radio", "onCheckedChanged checkId = "+checkedId);
            }
        });

        radioGroup.check(radioC.getId());
    }
}

My question is that, when this Activity start, I think I can get the Log only once, but I got twice:

07-19 12:26:30.765 I/radio: onCheckedChanged checkId = 2131493018
07-19 12:26:30.765 I/radio: onCheckedChanged checkId = 2131493018

2131493018 is the id of the radioC. But when I touch the screen to check a radioButton, onCheckedChanged called once.

Anyone can help with this ? thanks.

L. Swifter
  • 3,179
  • 28
  • 52

0 Answers0