Image Not Loading From Url In Custom Infowindow Using Picasso Image Loading Library In Android
I am trying to load an image from the URL in custom infoWindow when the user click on the marker. I was able to load the other details but the image is not loading int it. i'm usin
Solution 1:
You can use a Picasso Callback onsuccess loading the image, like this
if (image != null) {
Picasso.with(getApplicationContext())
.load(image)
.placeholder(R.drawable.ic_launcher)
.into(i, new MarkerCallback(marker));
}
and create a new class to handle the Picasso Callback like this MarkerCallback.java
publicclassMarkerCallbackimplementsCallback {
Marker marker=null;
MarkerCallback(Marker marker) {
this.marker=marker;
}
@OverridepublicvoidonError() {
Log.e(getClass().getSimpleName(), "Error loading thumbnail!");
}
@OverridepublicvoidonSuccess() {
if (marker != null && marker.isInfoWindowShown()) {
marker.hideInfoWindow();
marker.showInfoWindow();
}
}
}
Solution 2:
mMap.setInfoWindowAdapter(object : GoogleMap.InfoWindowAdapter { override fun getInfoContents(p0: Marker?): View? { return null }
overridefungetInfoWindow(p0: Marker?): View? {
if (p0!!.tag != null) {
val view = LayoutInflater.from(this@ProviderMainActivity).inflate(R.layout.infowindow_client, null)
val text = view.findViewById<TextView>(R.id.TXT_NAME)
val TXT_location = view.findViewById<TextView>(R.id.TXT_location)
val proimg = view.findViewById<ImageView>(R.id.IMG)
val datares = p0!!.tag as ResponseDataItem
Glide.with(this@ProviderMainActivity).load(datares.user!!.profileImageWithURL)
.apply(RequestOptions.circleCropTransform().override(50,50).placeholder(R.drawable.placeholder_profile))
.listener(object :RequestListener<Drawable>{
overridefunonLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
returntrue
}
overridefunonResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
Klog.d("## FIRST RESOURCE-","-".plus(isFirstResource))
Klog.d("## FIRST DATA SOURCE-","-".plus(dataSource?.name))
proimg.setImageDrawable(resource)
if (dataSource?.name.equals("DATA_DISK_CACHE")) {
p0.showInfoWindow()
}
returntrue
}
}).into(proimg)
text.setText(datares.user!!.fullName)
var loc = datares.location!!.text!!.split(",").map { it.trim() }
TXT_location.setText(loc.get(0))
return view
} else {
returnnull
}
}
})
Solution 3:
Superb ans. work perfectly and easy to implement.
Post a Comment for "Image Not Loading From Url In Custom Infowindow Using Picasso Image Loading Library In Android"