Search code examples
javaandroidradio-button

Show views depending on radio button selection


Thank you for understanding my lack of English skills.

I am working on an android app in java. Is there a way to change the group of 6 buttons according to the selection of A Radio button and B Radio button?

enter image description hereenter image description here

I didn't try because I didn't have a good idea.


Solution

  • you can simply add in you XML layout two different radio groups, with their personal ID. So, based on check selected, you hide and show the correct radio-groups.

    Example:

    radioA.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    
           @Override
           public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
    //show groupA
    //hide groupB
           }
       }
    );     
    
    
    
    radioB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        
               @Override
               public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
        //show groupB
        //hide groupA
               }
           }
        );