Picasso java.lang.IllegalStateException: Method call should not happen from the main thread

后端 未结 5 2006
后悔当初
后悔当初 2021-01-07 22:32

I am attempting to use Picasso to get three Bitmap images from a URL

public void onCreate(Bundle savedInstanceState) { 
  super.onC         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 23:35

    This is the same answer of Juan José Melero Gómez but with kotlin:

    val imageBitmap = Picasso.get().load(post.path_image).into(object: Target {
            override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
                Log.(TAG, "Getting ready to get the image");
                 //Here you should place a loading gif in the ImageView
                 //while image is being obtained.
            }
    
            override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
                Log.e(TAG, "The image was not obtained");
            }
    
            override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
                Log.i(TAG, "The image was obtained correctly");
            }
    
        })
    

提交回复
热议问题