Example usage for android.widget RadioGroup getTag

List of usage examples for android.widget RadioGroup getTag

Introduction

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

Prototype

public Object getTag(int key) 

Source Link

Document

Returns the tag associated with this view and the specified 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/*from w w w  .  j  a va 2s.  c  o 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;
        }
    }
}