Event to detect loaded image GLIDE

2

I am using the Glide library to display images, like this:

GlideApp.with(this).load("https://i1.wp.com/blogthinkbig.com/wp-content/uploads/2015/07/shutterstock_148972376.jpg").into(imageView);

How I can tell when the image finished loading

    
asked by programadorloco 05.12.2017 в 05:57
source

3 answers

-1

You can use the callbacks Glide has. In the documentation of it you can find more information or do something like the following:

progressBar.setVisibility(View.VISIBLE);
Glide.with(getActivity())
 .load(args.getString(IMAGE_TO_SHOW))
 .listener(new RequestListener<String, GlideDrawable>() {
     @Override
     public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
         return false;
     }

     @Override
     public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
         progressBar.setVisibility(View.GONE);
         return false;
     }
 })
 .into(imageFrame);

Source: link

    
answered by 05.12.2017 / 19:14
source
0

You can create a statement, you can use a try catch or a if

try {
   GlideApp.with(this).load("https://i1.wp.com/blogthinkbig.com/wp-content/uploads/2015/07/shutterstock_148972376.jpg").into(imageView);
} catch (Exception e) {
   Toast toast1 = Toast.makeText(getApplicationContext(), "No se puedo cargar la imagen", Toast.LENGTH_SHORT);  

     return null;
}

On the other hand if you want to create a more complex solution you could use a Progressbar with this you show the loading of the image in real time to the user, instead with the solution above ( try catch ) will show a message to the I finish the task.

    
answered by 05.12.2017 в 06:42
0

Using Glide , to detect that we upload an image, use onResourceReady () , according to your code, it would be:

    Glide.with(this)
            .load("https://i1.wp.com/blogthinkbig.com/wp-content/uploads/2015/07/shutterstock_148972376.jpg")
            .into(new GlideDrawableImageViewTarget(imageView) {
                @Override
                public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
                    super.onResourceReady(drawable, anim);

                    //*Aquí determina la carga del recurso.
                    Log.i(TAG, "La imagen ha sido cargada por Glide!");

                }
            });
    
answered by 05.12.2017 в 19:08