2016-07-16 11 views
0

Ich habe fünf BadioButton in RadioGroup. Nun, was ich will, dass, wenn ich "NDS" vom Web Service bekomme, dann wird die Show "NDS" RadioButton aktiviert oder wenn ich "DS" erhalte, dann wird seine Show "DS" überprüft. Wie kann ich das erreichen?Wie zeigt Radio Button Eingecheckte Radiogruppe an, wenn Wert von Web Service abgerufen wird?

Unten ist mein Radio Group XML-Code:

<RadioGroup android:id="@+id/rdoCnsumerCatgory" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:orientation="horizontal"> 

      <RadioButton android:id="@+id/rdoDS" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:text="DS" 
       android:layout_marginLeft="20dp" 
       android:textColor="#000000" 
       android:textSize="10sp" 
       android:textStyle="bold" /> 

      <RadioButton android:id="@+id/rdoNDS" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginLeft="20dp" 
       android:gravity="center" 
       android:text="NDS" 
       android:textColor="#000000" 
       android:textSize="10sp" 
       android:textStyle="bold" /> 

      <RadioButton android:id="@+id/rdoSip" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginLeft="20dp" 
       android:gravity="center" 
       android:text="SIP" 
       android:textColor="#000000" 
       android:textSize="10sp" 
       android:textStyle="bold" /> 

      <RadioButton android:id="@+id/rdoMip" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:layout_marginLeft="20dp" 
       android:text="MIP" 
       android:textColor="#000000" 
       android:textSize="10sp" 
       android:textStyle="bold" /> 

      <RadioButton android:id="@+id/rdoMl" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:text="ML" 
       android:layout_marginLeft="20dp" 
       android:textColor="#000000" 
       android:textSize="10sp" 
       android:textStyle="bold" /> 
     </RadioGroup> 
+0

Versuch, wenn sonst conition oder Zustand wechseln –

Antwort

0

Try This

Durch if-else-Methode

String mValue=""; 


     RadioButton rdoMl,rdoMip,rdoSip,rdoNDS,rdoDS; 
     if(mValue.equalsIgnoreCase("NDS")) 
     { 
      rdoNDS.setChecked(true); 
     } 
     else if(mValue.equalsIgnoreCase("DS")) 
     { 
      rdoDS.setChecked(true); 
     } 
     else if(mValue.equalsIgnoreCase("MIP")) 
     { 
      rdoMip.setChecked(true); 
     } 
     else if(mValue.equalsIgnoreCase("SIP")) 
     { 
      rdoSip.setChecked(true); 
     } 
     else if(mValue.equalsIgnoreCase("ML")) 
     { 
      rdoMl.setChecked(true); 
     } 

Durch Schalter Methode

 switch(mValue) { 
      case "NDS": 
       rdoNDS.setChecked(true); 
       break; 
      case "DS": 
       rdoDS.setChecked(true); 
       break; 
      case "MIP": 
       rdoMip.setChecked(true); 
       break; 
      case "SIP": 
       rdoSip.setChecked(true); 
       break; 
      case "ML": 
       rdoMl.setChecked(true); 
       break; 

      // etc... 
     }