Search code examples
androidcheckboxviewvisibleandroid-radiobutton

Radio Button Selection in Android


In my project I have two radio button under a radio group.By default the first radio button is selected.When first radio button is in selected state four checkboxes will be visible if second radio button is in selected state all four checkboxes will be gone to invisible state.I dont know how to implement this.Can anyone suggest me?

Thank you!!!


Solution

  • Its too simple. Earlier you mentioned that first time your first radio button is selected then at that time you have to just set visibility for checkboxes visible. Like

     ch1.setVisibility(View.VISIBLE); // same for other checkboxes
    

    And when you select second radio button at that time set visibility for that check boxes GONE. Like

     ch1.setVisibility(View.GONE);   // same for other checkboxes
    

    UPDATE:

     radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // TODO Auto-generated method stub
            if(checkedId == R.id.urfirstR1)
              {
                    ch1.setVisibility(View.VISIBLE);
    
           else if(checkedId == R.id.ursecondr2)
              {
                    ch1.setVisibility(View.GONE); 
              }
        }
    });