[英]How to load image from url into imageview in widget using picasso
I tried to load the image into the imageview on the widget using Picasso but when i run imageview return blank, no image is displayed just white blank我尝试使用毕加索将图像加载到小部件上的图像视图中,但是当我运行图像视图返回空白时,没有图像显示为白色空白
this is my code这是我的代码
internal class StackRemoteViewsFactory(private val context: Context, intent: Intent) :
RemoteViewsService.RemoteViewsFactory {
private val appWidgetId: Int = intent.getIntExtra(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID
)
......
override fun getViewAt(position: Int): RemoteViews {
val rv = RemoteViews(context.packageName, R.layout.widget_favorite_item)
GlobalScope.launch(Dispatchers.Main) {
Picasso.get().load(data[position].image_path)
.into(rv, R.id.img_widget_banner, intArrayOf(appWidgetId))
}
return rv
}
}
I think the problem is in your Picasso code.我认为问题出在您的毕加索代码中。 First check data[position].imagepath return the correct image path.
首先检查 data[position].imagepath 返回正确的图像路径。 If you still have the problem then try to show image into only one view.
如果问题仍然存在,请尝试仅在一个视图中显示图像。 For example you use: rv is a image view
例如你使用: rv 是一个图像视图
Picasso.get()
.load(data[position].image_path)
.into(rv)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.