[英]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.