Example usage for android.widget RadioGroup setTag

List of usage examples for android.widget RadioGroup setTag

Introduction

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

Prototype

public void setTag(int key, final Object tag) 

Source Link

Document

Sets a tag associated with this view and a key.

Usage

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/*  w  w w .j  a  va  2s  .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;
        }
    }
}