小编A B*_*A B的帖子

取消选中单选按钮

该应用程序是一个步进音序器应用程序,具有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);
            }
        });
Run Code Online (Sandbox Code Playgroud)

android if-statement radio-button checked uncheck

4
推荐指数
1
解决办法
2万
查看次数

Android单选按钮取消选中

该应用程序是一个步进音序器应用程序,具有16个无线电组,每组有8个按钮.除非我使用我创建的清除按钮清除所有放射线组,否则除非一个组选择了一个按钮,否则它可以完美地工作.我想要添加的是一些代码,表示当再次选择所选单选按钮时,它会像切换一样关闭.我尝试使用切换,但随后出现了其他问题.下面是两次尝试,但两个都只是阻止我使用按钮

     final RadioGroup radioGroup1 = (RadioGroup)findViewById(R.id.RadioGroup1);
     RadioButton D1 = (RadioButton)findViewById(R.id.RadioButtonD1);

     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(D1 != null) // This will be null if none of the radio buttons are selected
                   radioGroup1.clearCheck(); 
            PdBase.sendFloat("D1", 0);
        }
    });

RadioButton lC1 = (RadioButton)findViewById(R.id.RadioButtonlowC1);
        lC1.setOnClickListener(new View.OnClickListener() {



            public void onClick(View v) {

                 int selectedTypeId = radioGroup1.getCheckedRadioButtonId();

                RadioButton lC1 = (RadioButton) findViewById(R.id.RadioButtonlowC1);
                if (selectedTypeId == -1){ …
Run Code Online (Sandbox Code Playgroud)

android button radio

4
推荐指数
3
解决办法
1万
查看次数

标签 统计

android ×2

button ×1

checked ×1

if-statement ×1

radio ×1

radio-button ×1

uncheck ×1