android-databinding
How to bind method on RadioGroup on checkChanged event with data-binding
After digging to the bunch of methods, I found this question on SO which helped me understand how to bind single methods of listeners. Here is what to do with RadioGroup: In RadioGroup listener you have a method onCheckedChanged(RadioGroup g, int id). So you can directly bound that method to your handler or your activity … Read more
ClassNotFoundException: Didn’t find class “android.databinding.DataBinderMapper”
Make sure that ALL your modules that use DataBinding have it enabled. This was the reason I got that exception. android { …. dataBinding { enabled = true } }
Using attribute resources (?attr/) in layout binding?
If @{android.R.attr.textColorPrimary} resolves to the value of android.R.attr.textColorPrimary in Java, all you need to do is resolve that to a color. There’s a bit of a setup going into this. ContextUtils.java The following method resolves supplied attr of context‘s theme and optional style to a color. Falls back to fallback color if there’s an error. … Read more
Android data binding “Missing import expression although it is registered” after upgrade to gradle 5.0
After I upgraded my Android studio and gradle plugin, I ran into similar issue because of the below line. I was using this <import type=”java.lang.String” /> in my layout file. Removing this import solved the issue. Just as in managed code, java.lang.* is imported automatically.
android:entries in recyclerview
As correctly explained in the other answers there isn’t an attribute to fill the RecyclerView from xml. However using the Android Databinding you can create a similar attribute quite easily: <?xml version=”1.0″ encoding=”utf-8″?> <layout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto”> <android.support.v7.widget.RecyclerView android:layout_width=”match_parent” android:layout_height=”match_parent” app:entries=”@{@stringArray/fi}” app:layoutManager=”android.support.v7.widget.LinearLayoutManager”/> </layout> Here the binding adapter definition: import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter(“entries”) public … Read more
Include tag and dataBinding
You can pass that from parent.xml <include layout=”@layout/custom” android:id=”@+id/layout1″ app:user=”@{object of user1`}”/> <include layout=”@layout/custom” android:id=”@+id/layout2″ app:user=”@{object of user2`}”/> Here you need to pass User object from parent.xml Make sure you have <data> in custom.xml <data> <variable name=”user” type=”com.myproject.model.User”/> </data> Here is detailed answer related to this, refer it
Where to place android BindingAdapter method?
After navigating through the internet I’ve finally found some info from one of the developers themselves. I wish they would have been more clear on the basics in the documentation. Quote: Binding adapters are annotated methods in any class that are used to do just this. Typically, you’d organize your adapters into [-a] classes based … Read more