android onCheckedChanged for radiogroup

前端 未结 6 1708
死守一世寂寞
死守一世寂寞 2021-01-07 16:39

I\'m writing an Activity in android where I have two radio buttons under a RadioGroup. One of them is checked by default. But I can\'t trigger the event in

6条回答
  •  轮回少年
    2021-01-07 17:28

     radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
    
                if (checkedId == R.id.radioButton1) {
                 //do work when radioButton1 is active
                } else  if (checkedId == R.id.radioButton2) {
                 //do work when radioButton2 is active
              } else  if (checkedId == R.id.radioButton3) {
                 //do work when radioButton3 is active
              }
    
            }
        });
    

    this work for me . hope is helpfull

提交回复
热议问题