简体   繁体   English

如何检查单选按钮是否在单选组中被选中

[英]How to check if a radiobutton is checked in a radio group

I want to turn off the music when rbtOff is clicked. 单击rbtOff时,我想关闭音乐。 I tried this code but it didn't work - it still kept playing the music after I clicked off button. 我尝试了这段代码,但是没有用-单击关闭按钮后,它仍然继续播放音乐。

BGM.java BGM.java

RadioButton rbtOn, rbtOff;
MediaPlayer bgm;
    ......

bgm = MediaPlayer.create(BGM.this, R.raw.ny);
    bgm.setLooping(true);
    bgmstart();
    //bgmStop();*/
}

public void bgmstart() {
    RadioButton rbtOn = (RadioButton) findViewById(R.id.rbtOn);
    RadioButton rbtOff = (RadioButton) findViewById(R.id.rbtOff);
    if (rbtOff.isChecked())
    {
        bgm.release();
        bgm = null;
    }
    else if (rbtOn.isChecked())
    {
        bgm.start();
    }

try using bgm.stop(); 尝试使用bgm.stop(); and then bgm.release(); 然后bgm.release();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查“单选按钮”是否被选中? - How to check if "Radiobutton" is checked? 如何检查单选按钮是否选中? - How check radio buttons checked or not? 如果选中单选按钮,如何检查复选框 - How to check checkbox if radio button is checked 如何设置选中的单选按钮状态。 不使用广播组 - How to set checked radio button state . not using radio group 更改单选按钮选中状态时如何从单选按钮组中的单选按钮获取文本 - How to get the text from radio button in a radio group when radio button checked state is changed 在 Android 中选中单选按钮时,如何取消选中单选组中的所有单选按钮? - How to uncheck all radio buttons in a radio group, when a radio button is checked in Android? 如何检查每个无线电组中的按钮是否被选中? - How to check is the button is selected in each radio group? 如何检查按下按钮时选中了哪些单选按钮 - How to check which radio buttons are checked upon pressing a button 如何检查另一个活动中选中了哪个单选按钮,然后在IF语句中使用? - How to check which radio button is checked in another activity, and then use in IF Statement? 如何获取从 Android 中的单选组检查的最后一个单选按钮? - How do i get the last radio button that was checked from a radio group in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM