Ad
****/ Data Binding Error ****msg:Cannot Find The Setter For Attribute 'app:image_url' With Parameter Type Java.lang.String On Android.widget.ImageView
Getting stuck imageview databindig below are my custom adapter and Imageview. I refer to this [https://stackoverflow.com/questions/40188894/cannot-find-the-setter-for-attribute-with-parameter] but not getting solution - can anyone help? Thanks.
@BindingAdapter("app:image_url")
fun loadImage(view: ImageView, logoUrl: String?) {
if (logoUrl == null) {
view.setImageResource(R.drawable.alert_dark_frame)
} else {
Picasso.with(view.getContext())
.load(logoUrl)
.placeholder(R.mipmap.sym_def_app_icon)
.into(view)
}
}
<data>
<import type="android.view.View" />
<variable name="abc"
type="com.example.viewmodel.Result"/>
</data>
<ImageView
android:id="@+id/circleImageView"
android:layout_width="100dp"
android:layout_height="100dp"
app:image_url="@{abc.picture.thumbnail}"
/>
Ad
Answer
This is normal error because the class ImageView
doesn't contain a method setImageUrl
, so you need to do a workaround for that by creating a class that extends ImageView
and contains a method named setImageUrl
that takes a String
as parameter and set the image inside that method using Picasso
library:
public class MyImageView extends ImageView {
// ... here is the constructors
public void setImageUrl(String url) {
Picasso.get().load(url).into(this);
}
}
and after that you can use it in the xml like this:
<com.yourPackage.MyImageView
android:id="@+id/circleImageView"
android:layout_width="100dp"
android:layout_height="100dp"
app:image_url="@{abc.picture.thumbnail}"
/>
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad