Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Support for Data Binding Library #24

Description

@MihailsKuzmins

I tried to use com.github.angads25.toggle.widget.LabeledSwitch with the Data Binding Library and I got the following error in the build:
android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:Could not find event 'android:onAttrChanged' on View type 'com.github.angads25.toggle.widget.LabeledSwitch'

What I have tried is:
<com.github.angads25.toggle.widget.LabeledSwitch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:textOn="Yes"
app:textOff="No"
android:checked="@={isChecked}"/>

or

<com.github.angads25.toggle.widget.LabeledSwitch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:textOn="Yes"
app:textOff="No"
app:on="@={isChecked}"/>

and my binding adapters look like this:
@BindingAdapter("android:checked") // or "on"
public static void setChecked(LabeledSwitch view, Boolean isChecked) {
boolean blnValue = isChecked == null ? false : isChecked;
view.setOn(blnValue);
}

@InverseBindingAdapter(attribute = "android:checked") // or "on"
public static Boolean isChecked(LabeledSwitch view) {
return view.isOn();
}

What I had to do is 1) inherit from LabeledSwitch ; and 2) create this empty method:
public void onAttrChanged(final InverseBindingListener attrChange) { }

Setting a listener in the method resulted in the behaviour that the switch was changed its value twice (e.g. false -> true -> false). Example: setOnClickListener(v -> setOn(!isOn));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions