简体   繁体   中英

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. If you still have the problem then try to show image into only one view. For example you use: rv is a image view

Picasso.get()
.load(data[position].image_path)
.into(rv)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM