0

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

ir2pid
  • 5,604
  • 12
  • 63
  • 107

1 Answers1

2

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
    }
}
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
Keshav Aggarwal
  • 754
  • 6
  • 14