Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:为什么单选组中的单选按钮对于所选的任何项目总是返回false?_Android_Radio Button_Android Radiogroup - Fatal编程技术网

Android:为什么单选组中的单选按钮对于所选的任何项目总是返回false?

Android:为什么单选组中的单选按钮对于所选的任何项目总是返回false?,android,radio-button,android-radiogroup,Android,Radio Button,Android Radiogroup,我在一个单选组中有两个单选按钮,当我选择任何一个单选按钮并尝试使用isselected方法获取布尔值时,我总是得到假值。 为什么会发生这种情况。请帮助我。使用以下方法: radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton btn, boolean isCheck) { //ha

我在一个单选组中有两个单选按钮,当我选择任何一个单选按钮并尝试使用isselected方法获取布尔值时,我总是得到假值。 为什么会发生这种情况。请帮助我。

使用以下方法:

radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton btn, boolean isCheck) {

            //handle the boolean flag here. 
              if(isCheck==true)
                     //Do something

            else 
                //do something else

        }
    });
int selectedRbBtn = radiogroup.getCheckedRadioButtonId();
资料来源:

也许这会有所帮助

int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();
View radioButton = radioButtonGroup.findViewById(radioButtonID);
然后使用单选按钮执行您想要的任何任务

来源:

请使用以下内容:

radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton btn, boolean isCheck) {

            //handle the boolean flag here. 
              if(isCheck==true)
                     //Do something

            else 
                //do something else

        }
    });
int selectedRbBtn = radiogroup.getCheckedRadioButtonId();

如果它返回
-1
则未选择任何内容…

我也有同样的问题,isSelected方法不起作用。 isChecked方法对我很有效:

if(myRadioButton.isChecked()){
//做事
}否则{
//做其他事情

}

检查isChecked属性:@bobmaloga感谢它的工作。