选择两个无线电组按钮之间的单选按钮

时间:2014-08-17 18:39:29

标签: android

我有2个放射性组,每组包含5个单选按钮。 任何时候都只能选择一个10个单选按钮。我编写了下面的代码,它有一段时间而且并非总是如此。需要帮助。谢谢

radGrp1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {       
        @Override
        public void onCheckedChanged(RadioGroup arg0, int id) {


              id =arg0.getCheckedRadioButtonId();
             RadioButton selectedRedioButton = (RadioButton) findViewById(id);
             selectedRedioButton.setChecked(true);
             int checkedRadioButtonID = radGrp2.getCheckedRadioButtonId();
             //Toast.makeText(getApplicationContext(), "You have selected "+selectedRedioButton.getText().toString(), Toast.LENGTH_LONG).show();

             int checkedRadioButtonID2 = radGrp2.getCheckedRadioButtonId(); 
             if (checkedRadioButtonID2 != -1) {
                 RadioButton selectedRedioButton2 = (RadioButton) findViewById(checkedRadioButtonID2);
                 selectedRedioButton2.setChecked(false);     
             }

        }




    });

    radGrp2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup arg0, int id) {


            id =arg0.getCheckedRadioButtonId();
             RadioButton selectedRedioButton = (RadioButton) findViewById(id);
             selectedRedioButton.setChecked(true);
             int checkedRadioButtonID = radGrp2.getCheckedRadioButtonId();
             //Toast.makeText(getApplicationContext(), "You have selected "+selectedRedioButton.getText().toString(), Toast.LENGTH_LONG).show();

             int checkedRadioButtonID1 = radGrp1.getCheckedRadioButtonId(); 
             if (checkedRadioButtonID1 != -1) {
                RadioButton selectedRedioButton1 = (RadioButton) findViewById(checkedRadioButtonID1);
                selectedRedioButton1.setChecked(false);          

             }

        }


    });

0 个答案:

没有答案