Example usage for android.widget RadioGroup getChildAt

List of usage examples for android.widget RadioGroup getChildAt

Introduction

In this page you can find the example usage for android.widget RadioGroup getChildAt.

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:Main.java

public static void checkRadioGroup(RadioGroup radioGroup, String selectedRadioText) {
    for (int i = 0; i < radioGroup.getChildCount(); i++) {
        RadioButton radio = (RadioButton) radioGroup.getChildAt(i);
        if (radio.getText().equals(selectedRadioText)) {
            radioGroup.check(radio.getId());
            break;
        }//from www. j  a  va2s .c om
    }
}

From source file:Main.java

/**
 * Enables/Disables input view according to the state of the survey.
 * Sent surveys cannot be modified.//ww w .  j a v  a  2  s  .  c o m
 *
 * @param view
 */
public static void updateReadOnly(View view, boolean readOnly) {
    if (view == null) {
        return;
    }

    if (view instanceof RadioGroup) {
        RadioGroup radioGroup = (RadioGroup) view;
        for (int i = 0; i < radioGroup.getChildCount(); i++) {
            radioGroup.getChildAt(i).setEnabled(!readOnly);
        }
    } else {
        view.setEnabled(!readOnly);
    }
}

From source file:Main.java

/**
 * Utility method to uncheck all radio buttons in 
 * radio group//w  ww.j a  v a  2s  . com
 */
public static void toggleRadioButtonsEnabledState(RadioGroup radioGroup, boolean enabled) {
    for (int radioButtonCounter = 0; radioButtonCounter < radioGroup.getChildCount(); radioButtonCounter++) {
        RadioButton radioButton = (RadioButton) radioGroup.getChildAt(radioButtonCounter);
        radioButton.setEnabled(enabled);
    }
}

From source file:Main.java

public static List<RadioButton> getRadioButtons(RadioGroup radioGroup) {
    final ArrayList<RadioButton> out = new ArrayList<>(radioGroup.getChildCount());
    for (int i = 0; i < radioGroup.getChildCount(); i++) {
        final View v = radioGroup.getChildAt(i);
        if (v instanceof RadioButton) {
            out.add((RadioButton) v);//from  w w  w  .j  a  v a2 s  .  co  m
        }
    }
    return out;
}

From source file:Main.java

public static ArrayMap<Integer, RadioButton> getRadioButtonsMap(RadioGroup radioGroup) {
    final ArrayMap<Integer, RadioButton> out = new ArrayMap<>(radioGroup.getChildCount());
    for (int i = 0; i < radioGroup.getChildCount(); i++) {
        final View v = radioGroup.getChildAt(i);
        if (v instanceof RadioButton) {
            out.put(v.getId(), (RadioButton) v);
        }//from  w  w w  .  j ava  2  s . c o m
    }
    return out;
}

From source file:Main.java

/**
 * Detect name.//  ww  w . j ava 2s .c o m
 *
 * @param view the view
 * @return the string
 */
public static String detectName(View view) {
    String name = new String();
    if (view instanceof TextView) {
        name = ((TextView) view).getText().toString();
        if (view instanceof EditText) {
            CharSequence hint = ((EditText) view).getHint();
            name = (hint == null) ? new String() : hint.toString();
        }
        return name;
    }
    if (view instanceof RadioGroup) {
        RadioGroup group = (RadioGroup) view;
        int max = group.getChildCount();
        String text = new String();
        for (int item = 0; item < max; item++) {
            View child = group.getChildAt(item);
            text = detectName(child);
            if (!text.equals("")) {
                name = text;
                break;
            }
        }
    }
    return name;
}

From source file:it.cosenonjaviste.twowaydatabinding.DataBindingConverters.java

@BindingAdapter({ "app:binding" })
public static void bindRadioGroup(RadioGroup view, final ObservableString observableString) {
    if (view.getTag(R.id.bound_observable) != observableString) {
        view.setTag(R.id.bound_observable, observableString);
        view.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override/*from w  ww .  jav a2s.co  m*/
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                for (int i = 0; i < group.getChildCount(); i++) {
                    final View child = group.getChildAt(i);
                    if (checkedId == child.getId()) {
                        observableString.set(child.getTag().toString());
                        break;
                    }
                }
            }
        });
    }
    String newValue = observableString.get();
    for (int i = 0; i < view.getChildCount(); i++) {
        final View child = view.getChildAt(i);
        if (child.getTag().toString().equals(newValue)) {
            ((RadioButton) child).setChecked(true);
            break;
        }
    }
}

From source file:com.github.dfa.diaspora_android.ui.theme.ThemeHelper.java

public static void updateRadioGroupColor(RadioGroup radioGroup) {
    if (radioGroup != null && Build.VERSION.SDK_INT >= 21) {
        for (int i = 0; i < radioGroup.getChildCount(); ++i) {
            RadioButton btn = ((RadioButton) radioGroup.getChildAt(i));
            btn.setButtonTintList(new ColorStateList(
                    new int[][] { new int[] { -android.R.attr.state_enabled },
                            new int[] { android.R.attr.state_enabled } },
                    new int[] { Color.BLACK, ThemeHelper.getAccentColor() }));
            btn.invalidate();/*from ww  w  .  j  av  a2  s . c o  m*/
        }
    }
}

From source file:com.microsoft.band.sdksample.SensorsFragment.java

private static void setChildrenEnabled(RadioGroup radioGroup, boolean enabled) {
    for (int i = radioGroup.getChildCount() - 1; i >= 0; i--) {
        radioGroup.getChildAt(i).setEnabled(enabled);
    }//from w w w . j  a v  a 2 s.c o m
}

From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java

public static String getTextOfView(View view) {
    Object textObj = null;/* www .j  a  v a2s.  c o  m*/
    if (view instanceof TextView) {
        textObj = ((TextView) view).getText();

        if (view instanceof Switch) {
            boolean isOn = ((Switch) view).isChecked();
            textObj = isOn ? "1" : "0";
        }
    } else if (view instanceof Spinner) {
        Object selectedItem = ((Spinner) view).getSelectedItem();
        if (selectedItem != null) {
            textObj = selectedItem.toString();
        }
    } else if (view instanceof DatePicker) {
        DatePicker picker = (DatePicker) view;
        int y = picker.getYear();
        int m = picker.getMonth();
        int d = picker.getDayOfMonth();
        textObj = String.format("%04d-%02d-%02d", y, m, d);
    } else if (view instanceof TimePicker) {
        TimePicker picker = (TimePicker) view;
        int h = picker.getCurrentHour();
        int m = picker.getCurrentMinute();
        textObj = String.format("%02d:%02d", h, m);
    } else if (view instanceof RadioGroup) {
        RadioGroup radioGroup = (RadioGroup) view;
        int checkedId = radioGroup.getCheckedRadioButtonId();
        int childCount = radioGroup.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = radioGroup.getChildAt(i);
            if (child.getId() == checkedId && child instanceof RadioButton) {
                textObj = ((RadioButton) child).getText();
                break;
            }
        }
    } else if (view instanceof RatingBar) {
        RatingBar bar = (RatingBar) view;
        float rating = bar.getRating();
        textObj = String.valueOf(rating);
    }

    return textObj == null ? "" : textObj.toString();
}