I have create a binding adapter to display picture with picasso, but it doesn't work. I have the following error :
Found data binding errors. ****/ data binding error ****msg:Cannot find the setter for attribute 'app:loadPicture' with parameter type java.lang.String on android.widget.ImageView. file:/home/groupevsc.com/mathieu_labar/Documents/Projects/android-jetpack/app/src/main/res/layout/activity_detail_movie.xml loc:27:31 - 27:52 ****\ data binding error ****
Here is my binding adapter :
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)
}
}
And my XML has attribute "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}"/>
Here is my GitHub repository: https://github.com/mlabar/android-jetpack/tree/tech_ajout_databinding
Would anyone have an idea to solve my problem?
Thank you!
Binding adapters are responsible for making the appropriate framework calls to set values. One example is setting a property value like calling the setText() method. Another example is setting an event listener like calling the setOnClickListener() method.
Using data binding can lead to faster development times, faster execution times and more readable and maintained code. Android data binding generates binding classes at compile time for layouts.
Thank you @Blackbelt to solve my problem, i have added "kotlin-kapt" in all my build.gradle
modules:
apply plugin: 'kotlin-kapt'
Here is my code
@JvmStatic
@BindingAdapter({"bind:loadPicture"})
fun loadPicture(view: ImageView, loadPicture: String) {
Picasso.with(view.context)
.load(loadPicture)
.error(R.drawable.ic_movie_24)
.fit()
.placeholder(R.drawable.ic_movie_24)
.into(view)
}
for more details see my project on GitHub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With