我已经创建了一个绑定适配器来使用picasso显示图片,但是它不起作用。我有以下错误:
找到数据绑定错误。*/数据绑定错误*msg:无法找到属性'app:loadPicture‘的setter,参数类型为java.lang.String。file:/home/groupevsc.com/mathieu_labar/Documents/Projects/android-jetpack/app/src/main/res/layout/activity_detail_movie.xml loc:27:31-27:52*\数据绑定错误*
以下是我的绑定适配器:
object CommonBindingUtil {
    @JvmStatic
    @BindingAdapter("loadPicture")
    fun loadPicture(view: ImageView, text: String) {
        Picasso.with(view.context)
                .load(text)
                .error(R.drawable.ic_movie_24)
                .fit()
                .placeholder(R.drawable.ic_movie_24)
                .into(view)
    }
}我的XML有属性"app:loadPicture“:
<ImageView
    android:id="@+id/picture"
    android:layout_width="@dimen/material_image_simple_width"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:src="@drawable/ic_movie_24"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:loadPicture="@{viewModel.movie.Poster}"/>下面是我的GitHub存储库:数据库化
有人想办法解决我的问题吗?
谢谢!
发布于 2018-07-19 09:39:59
更改您的MovieViewModel类如下:
class MovieViewModel(private val movie: Movie) : Observer, BaseObservable() {
    init {
       Movie.addObserver(this)
    }
    val Poster: String
        @Bindable get() {
            return Poster.name
        }
}和电影这样的类:
class Movie: Observable() {
    var Title: String = ""
        set(value) {
            field = value
            setChangedAndNotify("Title")
        }
    var Year: String = ""
        set(value) {
            field = value
            setChangedAndNotify("Year")
        }
    var imdbID: String = ""
        set(value) {
            field = value
            setChangedAndNotify("imdbID")
        }
    var Type: String = ""
        set(value) {
            field = value
            setChangedAndNotify("Type")
        }
    var Poster: String = ""
        set(value) {
            field = value
            setChangedAndNotify("Poster")
        }
    var Plot: String = ""
        set(value) {
            field = value
            setChangedAndNotify("Plot")
        }
    private fun setChangedAndNotify(field: Any) {
        setChanged()
        notifyObservers(field)
    }
}根据你的需要建立你的课堂背景,运行它,希望它能解决你的问题。
https://stackoverflow.com/questions/51418542
复制相似问题