dimanche 20 décembre 2015

Three CheckBoxes in a settings screen only letting the user click one at a time

I have three CheckBoxes in a settings screen, but I only want the user to be allowed to click one. How can I make it so when the user clicks on one it unblocks the other. Here is my code in my main activity that connects the checkboxes to their sound value.

            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();
                    }

                }




Aucun commentaire:

Enregistrer un commentaire