Advertisement
B47CHGURU

setRadioGroupValues [codeGarage1]

Jan 26th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1.     /*
  2.      *
  3.      * Sets the Radiogroup button values to the desired.
  4.      * @Author: Daryl
  5.      * @Date: 26/01/2015
  6.      * @Prerequisite: android.widget.* |  java.util.ArrayList | org.json.*
  7.      * @Parameters: RadioGroup , JSONArray
  8.      *
  9.      */
  10.     public void setRadioGroupValues(RadioGroup radioGroup , JSONArray valueArray, Boolean disableEmptyBoxes){
  11.         int count = radioGroup.getChildCount();
  12.         int arraylength = valueArray.length();
  13.         //ArrayList<RadioButton> listOfRadioButtons = new ArrayList<RadioButton>();
  14.         for (int i=0;i<count;i++) {
  15.             View button = radioGroup.getChildAt(i);
  16.             if (button instanceof RadioButton) {
  17.                // listOfRadioButtons.add((RadioButton)o);
  18.                 logger.info("id:"+i+" "+((RadioButton) button).getText().toString());
  19.                 try{
  20.                     ((RadioButton) button).setText(((i > (arraylength - 1)) || (arraylength == 0)) ? "" : valueArray.getString(i));
  21.                     if(disableEmptyBoxes && ((RadioButton) button).getText().toString().isEmpty()){
  22.                         ((RadioButton) button).setVisibility(View.GONE);
  23.                     }else{
  24.                         ((RadioButton) button).setVisibility(View.VISIBLE);
  25.                     }
  26.                 }catch (Exception e) {
  27.                     logger.error("JSON parsing error " + e);
  28.                 }
  29.             }
  30.         }      
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement