如何检查状态更改单选按钮android?

时间:2017-08-14 16:19:07

标签: android radio-button

我想检查单击radioButton是否更改了某个值

这是我的代码:

new DynamicViews().makeRadioButton(getApplicationContext(),radioGroup,"Ok");
new DynamicViews().makeRadioButton(getApplicationContext(),radioGroup,"Ok");
RadioButton radioButton =
                        new DynamicViews().makeRadioButtonforAnswer(getApplicationContext(),radioGroup,"This is the answer");

前两个无线电是在没有引用的情况下创建的,但最后一个是我的答案,所以我得到一个参考来检查是否已经检查。

这是我的问题: 我如何检查radioButton是否被勾选?

   radioButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        goToNextLevel = true;
                    }
                });

这是我的方法到目前为止,但它不能完美地工作,因为当用户选择radioButton并且之后将改变他们的选择时goToNextLevel的值不会改变并且将以错误的方式设置为true。

如果只检查radioButton,如何找出goToNextLevel为true,否则为false。

1 个答案:

答案 0 :(得分:3)

首先创建RadioGroup如果您还没有这样做,那么像往常一样将其连接到id,然后使用setOnCheckedChangeListener。您可以选中是否检查RadioButton,也可以检查RadioButton以上radioGroup.setOnCheckedChangeListener(new new OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch(checkedId) { case R.id.firstRadioButton: //Implement logic break; case R.id.secondRadioButton: //Implement logic break; } } }); 。例如:

132 rockaway blvd -12345 , 176-58 bayshore avenue -78952, 12-89 rosedale place but I need to only display:
    132 rockaway blvd
    176-58 bayshore avenue
    12-89 rosedale place

I have tried `select distinct right(rtrim(placeName),7) from places` but this only gives me the last characters  -12345
相关问题