【发布时间】:2015-12-20 23:48:51
【问题描述】:
我在设置屏幕中有三个复选框,但我只希望允许用户单击一个。我怎样才能做到这一点,当用户单击一个时,它会取消阻止另一个。这是我的主要活动中的代码,它将复选框连接到它们的声音值。
standardSound = MediaPlayer.create(this, R.raw.fanpost);
alternateSound = MediaPlayer.create(this, R.raw.alternate_fan);
whiteSound = MediaPlayer.create(this, R.raw.white_noise);
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean alternate = getPrefs.getBoolean("alternate", false);
boolean white = getPrefs.getBoolean("white", false);
boolean standard = getPrefs.getBoolean("standard",false);
if (blade.getAnimation() == null) {
// no animation, start it
if (alternate == true) {
alternateSound.start();
alternateSound.setLooping(true);
blade.startAnimation(animRotate);
if (blade.getAnimation() == null) {
alternateSound.stop();
alternateSound.prepareAsync();
}
} else if (white == true) {
whiteSound.start();
whiteSound.setLooping(true);
blade.startAnimation(animRotate);
if (blade.getAnimation() == null) {
whiteSound.stop();
whiteSound.prepareAsync();
}
} else if (standardFan == true) {
standardSound.start();
standardSound.setLooping(true);
blade.startAnimation(animRotate);
if (blade.getAnimation() == null) {
standardSound.stop();
standardSound.prepareAsync();
}
}
【问题讨论】:
-
单选按钮就是为了做到这一点。
-
复选框代码部分在哪里?
-
sharedPreference 布尔值是复选框
-
那么你将如何使用单选按钮来处理这类事情
-
您希望用户只选择一个框还是允许从第一个选择中访问其他选项?
标签: android checkbox sharedpreferences