取消选中单选按钮[重复]

2024-03-22

该应用程序是一个步进音序器应用程序,具有 16 个无线电组,每组有 8 个按钮。它工作得很好,除非一个组选择了一个按钮,否则我无法将其关闭,除非我使用我创建的清除按钮来清除所有无线电组。我想添加的是一些代码,它表示当再次选择选定的单选按钮时,它会像切换一样关闭。我尝试使用切换开关,但该方法出现了其他问题。下面是一个尝试,但我猜它离目标还很远

final RadioGroup radioGroup1 = (RadioGroup)findViewById(R.id.RadioGroup1);
RadioButton lC1 = (RadioButton)findViewById(R.id.RadioButtonlowC1);

Button D1 = (Button)findViewById(R.id.RadioButtonD1);
        D1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                PdBase.sendFloat("D1", 74);
                int selectedTypeId = radioGroup1.getCheckedRadioButtonId();
                RadioButton D1 = (RadioButton) findViewById(selectedTypeId);
                if(radioGroup1 != null) // This will be null if none of the radio buttons are selected
                       radioGroup1.clearCheck(); 
                PdBase.sendFloat("D1", 0);
            }
        });

您需要将按钮放入单选组中,然后清除该组。单选按钮不能直接取消选中,因为其想法是始终选中一组中的一个选项。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

取消选中单选按钮[重复] 的相关文章

随机推荐