Android 我有多个复选框,但一次只希望单击其中一个复选框

Android 我有多个复选框,但一次只希望单击其中一个复选框,android,checkbox,android-preferences,Android,Checkbox,Android Preferences,我只是想让我的应用程序,让用户只能点击一个复选框的时间。因此,当用户点击其中一个复选框时,另两个复选框就会变成false。我尝试了一些方法,但似乎没有任何效果,而且我在网上也找不到任何相关信息。谢谢- 这是我的密码 public void buttonClick() { imgView = (ImageView) findViewById(R.id.imageView); button = (Button) findViewById(R.id.button)

我只是想让我的应用程序,让用户只能点击一个复选框的时间。因此,当用户点击其中一个复选框时,另两个复选框就会变成false。我尝试了一些方法,但似乎没有任何效果,而且我在网上也找不到任何相关信息。谢谢- 这是我的密码

   public void buttonClick() {
        imgView = (ImageView) findViewById(R.id.imageView);
        button = (Button) findViewById(R.id.button);
        blade = (ImageView)findViewById(R.id.imageView4);
        final Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
        standardSound = MediaPlayer.create(this, R.raw.file.mp3);
        alternateSound = MediaPlayer.create(this, R.raw.file.mp3);
        whiteSound = MediaPlayer.create(this, R.raw.file.mp3);

        button.setOnClickListener(

                new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        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();
                                blade.startAnimation(animRotate);



                            } else if (white == true){
                                whiteSound.start();
                                blade.startAnimation(animRotate);

                            } else if (standard == true) {
                                standardSound.start();
                                blade.startAnimation(animRotate);

                            }

                            } else {
                                //animation is showing, stop it
                                blade.clearAnimation();
                                standardSound.stop();
                                standardSound.prepareAsync();
                                whiteound.stop();
                                whiteSound.prepareAsync();
                                alternateSound.stop();
                                alternateSound.prepareAsync();

                            }





                        current_image_index++;
                        current_image_index = current_image_index % images.length;
                        imgView.setImageResource(images[current_image_index]);
                        imgView.invalidate();


                    }



                }
        );
    }
还有我的xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory
        android:title="Sound Settings">

        <CheckBoxPreference
            android:key="standard"
            android:title="Standard Fan"

            />
        <CheckBoxPreference
            android:key="alternate"
            android:title="Alternate Fan"

            />
        <CheckBoxPreference
            android:key="white"
            android:title="White Noise"
            />
    </PreferenceCategory>

</PreferenceScreen>

有一个名为windget的程序,它执行此功能

单选按钮允许用户从集合中选择一个选项。如果您认为用户需要并排查看所有可用选项,则应为互斥的可选集使用单选按钮


有一个windget调用,它执行此函数

单选按钮允许用户从集合中选择一个选项。如果您认为用户需要并排查看所有可用选项,则应为互斥的可选集使用单选按钮


然后,您可能希望将复选框更改为单选按钮。这样,您就不必担心其他复选框。如果可能重复,您可能需要将复选框更改为单选按钮。那么你就不必担心其他复选框了。你能把单选按钮放在偏好屏幕上吗?Leyton Taylor看看这个,我应该改进我的答案还是它对你有帮助?我只是好奇你如何把单选按钮放在偏好屏幕上?看我给你的教程你能放单选按钮吗按钮进入偏好屏幕?@Leyton Taylor看看这个,我应该改进我的答案还是它对你有帮助?我只是好奇你将如何在偏好屏幕中实现单选按钮?请参阅我给你的教程