简体   繁体   中英

How to check if a radiobutton is checked in a radio group

I want to turn off the music when rbtOff is clicked. I tried this code but it didn't work - it still kept playing the music after I clicked off button.

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(); and then bgm.release();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM