How to add a radio group to radio buttons inside of a table?

后端 未结 3 1887
感动是毒
感动是毒 2021-01-02 03:16

I have multiple radio buttons which I want to layout using a table but also include them in a single radio group. I have the following xml layout:



        
3条回答
  •  不知归路
    2021-01-02 03:46

    rg1 = (RadioGroup)findViewById(R.id.radioGroup1);
            rg2 = (RadioGroup)findViewById(R.id.radioGroup2);
            rg1.setOnCheckedChangeListener(this);
            rg2.setOnCheckedChangeListener(this);
        }
        boolean rg1b = false;
        boolean rg2b = false;
    
        @Override
        public void onCheckedChanged(RadioGroup rgId, int radioButtonId) {
            switch (rgId.getId()) {
            case R.id.radioGroup1:
                rg1b=true;
                if(rg2b)
                    rg2.clearCheck();
                break;
    
            case R.id.radioGroup2:
                rg1b=true;
                if(rg1b)
                    rg1.clearCheck();
                break;
            }
    

提交回复
热议问题