I'm using TypeConverter in some of my data-bindings. The issue is that it requires static functions and when I convert it into Kotlin it goes into the companion object and data-binding processor can't track the change.
I get the following error:
java.lang.IllegalStateException: Required DataBindingComponent is null in class ListMainBinding. A BindingAdapter in com.noisyninja.androidlistpoc.model.DataConverter.Companion is not static and requires an object to use, retrieved from the DataBindingComponent. If you don't use an inflation method taking a DataBindingComponent, use DataBindingUtil.setDefaultComponent or make all BindingAdapter methods static. at android.databinding.ViewDataBinding.ensureBindingComponentIsNotNull(ViewDataBinding.java:554)
How do I make it recognise static @TypeConverter annotated methods in companion object
You can add @jvmStatic annotation above the Binding Adapter method, something like this:
@BindingAdapter(value = "visiblity")
@JvmStatic
fun showHide(view : View, show : Boolean){
view.visibility = when {
show -> View.VISIBLE
else -> View.GONE
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.