Glide: Unable to use CustomViewTarget in code

Created on 20 Sep 2019  路  2Comments  路  Source: bumptech/glide

Version: 4.10.0
No integration libraries

Issue details / Repro steps / Use case background:
I have a custom view, that has a setImage(Bitmap) method. I'm using Kotlin. I was trying to load an image into said view by using:

Glide.with(this)
            .load(addSchemeIfNeeded(url))
            .into(object : CustomViewTarget<MyCustomView, Bitmap>(myCustomView) {
                override fun onLoadFailed(errorDrawable: Drawable?) {
                }

                override fun onResourceCleared(placeholder: Drawable?) {
                }

                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                    myCustomView.setImage(resource)
                }
            })

This results in a compilation error: Type mismatch: inferred type is but ImageView was expected.

Most helpful comment

I needed to add ".asBitmap()" to the builder calls.

All 2 comments

I needed to add ".asBitmap()" to the builder calls.

val target = Glide.with(this@MainActivity)
.asBitmap()
.load(item.mediaUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(object : CustomTarget() {
override fun onLoadCleared(placeholder: Drawable?) {
TODO("Not yet implemented")
}

            override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                TODO("Not yet implemented")
            }

        })
Was this page helpful?
0 / 5 - 0 ratings

Related issues

technoir42 picture technoir42  路  3Comments

billy2271 picture billy2271  路  3Comments

kenneth2008 picture kenneth2008  路  3Comments

mttmllns picture mttmllns  路  3Comments

Morteza-Rastgoo picture Morteza-Rastgoo  路  3Comments