2

I can load image path to imageView using Glide in this code:

GlideApp.with(context)
                .load(imagePath)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transition(withCrossFade())
                .into(imageView);

I do not want to load previously registered same path or bitmap from imageView.

==============UPDATE=================

I find this solution (thanks ADM):

Glide automatically performs setTag() function and when I call imageView.getTag() function, result is deriving SingleRequest which has loaded data (imagePath or bitmap).

But I can't access singleRequest model field, it is a private. How can I take singleRequest model field? Please help me.

Adinia
  • 3,722
  • 5
  • 40
  • 58
propoLis
  • 1,229
  • 1
  • 14
  • 48

3 Answers3

1

As discussed you should tag e url with view.setTag().

Here setTag(Object object) takes object as argument . Whenever we call getTag() we need to cast it. below is the example.

 view.setTag("htttp://www.imgur.3877383.jpg");
    String url =(String)view.getTag();
    if(url!=null){
        // Use the url
    }

Cause Argument is an Object so you can also add class object as tag.

   view.setTag(myPozo);
    MyPozo myPozo =(MyPozo)view.getTag();
    if(myPozo!=null){
        // Use the pozo
    }

Also i am not aware with the use of this . But if you are working on List (ListView or RecyclerView etc) then you can directly access the dataset attached with the view by position.

ADM
  • 20,406
  • 11
  • 52
  • 83
  • 1
    Glide automatically performs `setTag()` function and when I call `getTag()` function is deriving `SingleRequest`. Glide SingleRequest has a model which has loaded path or image bitmap but singleRequest model is private and I haven't access this model – propoLis Feb 26 '18 at 12:22
  • Yeah i doubted that . Sorry not much familiar with GLide .Anyway i will look into issue . – ADM Feb 26 '18 at 12:22
  • well there is also key implementation of `settag()`. See if it works out for you . https://developer.android.com/reference/android/view/View.html#setTag(int, java.lang.Object) . You can set your own tag . – ADM Feb 26 '18 at 12:30
  • Yeah I know but Glide does not allow me to use setTag function. Throw this exception: `java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting` – propoLis Feb 26 '18 at 12:35
  • Yeah that happens with image loaders . Here is the thing you need to edit your question with proper detail . Why you need this ? May be there is simple workaround . – ADM Feb 26 '18 at 12:38
  • [This](https://stackoverflow.com/a/35096552/4168607) might solve your problem . Take a good look at it . Glide migrate to `setTag(int id, Object value)` . Good luck – ADM Feb 26 '18 at 12:51
  • thank you very very much!! Sorrry, You have very tired – propoLis Feb 26 '18 at 12:59
0

you can't take "image path" from imageView by using Glide or any other libraries, one can set image bitmap or background in the imageView so you can get bitmap back from imageview if you want but you cannot get imagepath back from imageview. if you wants to remember image path with you are going to apply as a bitmap in imageview you can do it via add the image path to arraylist and use it when needed

Try this code :

Glide.with(this).load(Uri.parse(resultUri)).asBitmap().into(new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {

                    if (resource != null) {

                        myTouchView1.setImageBitmap(resource);
                    }
                }
            });
Milan Hirpara
  • 534
  • 4
  • 18
  • I do not want load previously registered same path or bitmap from imageView..What should I do for this? – propoLis Feb 26 '18 at 08:10
-2

You should read:

Guide Documentation

The imagepath will be something like:

String asseturl = "file:///android_asset/demo1.jpg";
Glide.with(context).load(asserturl)....
Tatsuya
  • 352
  • 4
  • 18
  • I do not want load previously registered same path or bitmap from imageView.What should I do for this? – propoLis Feb 26 '18 at 08:12