I am using Databinding library to update the views from view model object.
activity_main.xml
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.example.android.DataViewModel" />
</data>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingLeft="@{viewModel.setPaddingLeft}"
android:paddingRight="@{viewModel.setPaddingLeft}"/>
</layout>
ViewModel:
@BindingAdapter({"android:paddingLeft"})
public static void setPaddingLeft(View view, float paddingFloat) {
int padding = context.getResources().getDimension(R.dimen.padding);
view.setPadding(padding, view.getPaddingTop(), view.getPaddingRight(),
view.getPaddingBottom());
}
I am getting below error:
Found data binding error(s):
[databinding] {"msg":"Could not resolve com.example.android.DataViewModel.setPaddingLeft as an accessor or listener on the attribute."