Android RadioGroup checks more than one RadioButton?

前端 未结 3 1376
生来不讨喜
生来不讨喜 2021-01-25 20:44

I am using RadioGroup, added RadioButton rdbut to RadioGroup rdgrp like rdgrp.addView(rdbut).

   for(int j=0         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-25 21:09

    Use Some thing like this xml design in user layout file.

       
    
                
                
     
    

    and For Use this RadioGroup in Activity 's OnCreate() Method and findView like this

     mRadioGroup = (RadioGroup) this.findViewById(R.id.SelectLayout_Group);
    

    and Then Use Below Code With Your Require Change To Add Radio Button in One RadioGroup.Use Also Below Require Declaration for Create Radio Button Dynamically.

         ArrayList layoutlist = new ArrayList(3);
         int index = -1;
         LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    
    
       for (String layout : layoutlist) {
            RadioButton r = new RadioButton(this);
            index++;
            r.setText(layout);
            r.setId(index);
            r.setLayoutParams(lp);
            r.setTextAppearance(this, R.style.TextBase);
    
    
            mRadioGroup.addView(r);
    
    
        }
    

    So don't forget to add your String Value in layoutlist before for loop .and R.style is some Require Style for Text Show in RadioButton.

提交回复
热议问题