Search code examples
androidkotlinviewbuild.gradlekapt

Cannot find a getter for <ProgressBar android:visibility> that accepts parameter type 'androidx.databinding.ObservableField<java.lang.Boolean>'


Other questions have been solved by adding kotlin-kapt plugin to the gradle file but my issue doesn't seem to simply go away with that. I'm trying to set the visibility of the progress bar so that the user knows when the app is working in the background. I use databinding for that, but I get a compile error:

Cannot find a getter for that accepts parameter type 'androidx.databinding.ObservableField<java.lang.Boolean>'

I think neither string or integer values work there either. At least with the boolean method, it doesn't complain about the setter, only a getter. Although I have databinding used with other views and it's working great. This is how I implement my solution in HomeViewModel currently:

 @Bindable
    var barProgress = ObservableField<Boolean>()
    fun doSomething(){
        this.barProgress.set(true)
    }

    @BindingAdapter("android:visibility")
    fun setVisibility(view: View, visible: Boolean) {
        view.visibility = if (visible) View.INVISIBLE else View.VISIBLE
    }

And in layout file:

<ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="15dp"
            android:layout_marginLeft="15dp"
            app:layout_constraintStart_toEndOf="@+id/tag_button"
            app:layout_constraintTop_toBottomOf="@+id/editTextTextMultiLine"
            android:visibility="@={myViewModel.barProgress}" //--> this is where it complains />

so in my HomeViewModel I should be able to set barProgress to true or false.

my build.gradle:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
}

Any idea how I should go about doing it?


Solution

  • It simply worked with cleaning and rebuilding the project, also I don't know if it's related but I replaced:

    plugins {
        id 'com.android.application'
        id 'kotlin-android'
        id 'kotlin-kapt'
    }
    

    with:

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-kapt'
    

    not sure if that too contributed to solving it.