How to check if “Radiobutton” is checked?

前端 未结 10 428
萌比男神i
萌比男神i 2020-12-06 06:01

I would like to make a structure with the condition (if-else) RadioButton

I want that when the Radiobutton RB1 is selected, this function is ac

10条回答
  •  感情败类
    2020-12-06 06:47

    You can also maintain a flag value based on listener,

     radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
    
                    //handle the boolean flag here. 
                      if(arg1==true)
                             //Do something
    
                    else 
                        //do something else
    
                }
            });
    

    Or simply isChecked() can also be used to check the state of your RadioButton.

    Here is a link to a sample,

    http://www.mkyong.com/android/android-radio-buttons-example/

    And then based on the flag you can execute your function.

提交回复
热议问题