I've written my custom recyclerView and have got a problem. But when I wrote an annotation to mark a setter for my imageView I got a compilation error. Here are the source code and errors.
Error:
Cannot find a setter for <com.makeramen.roundedimageview.RoundedImageView app:imageURL> that accepts parameter type 'java.lang.String'
If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
Setter code:
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import java.lang.Exception
class BindingAdapters {
@BindingAdapter("imageURL")//compilation error
fun setImageURL(imageView: ImageView, URL: String?) {
imageView.alpha = 0f
try {
Picasso.get().load(URL).noFade().into(imageView, object : Callback {
override fun onSuccess() {
imageView.animate().setDuration(300).alpha(1f).start()
}
override fun onError(e: Exception) {
}
})
} catch (ignored: Exception) {
}
}
}
ImageView xml code:
<data>
<variable
name="eventShow"
type="course.ru.qsearcher.models.Event" />
</data>
........
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/imageEvent"
android:layout_width="@dimen/_70sdp"
android:layout_height="@dimen/_100sdp"
android:layout_marginStart="@dimen/_10sdp"
app:imageURL="@{eventShow.imagePath}"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:riv_corner_radius="@dimen/_4sdp" />
Event is a data class with some fields like the title of an event, description, image URL, and so on.
I didn't add the Kotlin plugin to my gradle file
apply plugin: "kotlin-kapt"
That solved my problem