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

Support for Data Binding Library #24

Open
MihailsKuzmins opened this issue Apr 24, 2019 · 0 comments
Open

Support for Data Binding Library #24

MihailsKuzmins opened this issue Apr 24, 2019 · 0 comments

Comments

@MihailsKuzmins
Copy link

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));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant