簡體   English   中英

找不到吸氣劑<progressbar android:visibility>接受參數類型'androidx.databinding.ObservableField<java.lang.boolean> '</java.lang.boolean></progressbar>

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

通過將kotlin-kapt插件添加到gradle文件中已經解決了其他問題,但我的問題似乎不僅僅是 go 解決了這個問題。 我正在嘗試設置進度條的可見性,以便用戶知道應用程序何時在后台運行。 我為此使用數據綁定,但出現編譯錯誤:

找不到接受參數類型'androidx.databinding.ObservableField<java.lang.Boolean>'的getter

我認為字符串或 integer 值在那里也不起作用。 至少使用 boolean 方法,它不會抱怨 setter,只會抱怨 getter。 盡管我將數據綁定與其他視圖一起使用並且效果很好。 這就是我目前在 HomeViewModel 中實現我的解決方案的方式:

 @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
    }

在布局文件中:

<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 />

所以在我的 HomeViewModel 中,我應該能夠將 barProgress 設置為 true 或 false。

我的build.gradle

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

知道我應該怎么做 go 嗎?

它只是用於清理和重建項目,我也不知道它是否相關但我替換了:

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

和:

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

不確定這是否也有助於解決它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM