Picture Loading Library glide--Resolve picture Confusion + Unable to set tag

Source: Internet
Author: User

Today in writing a picture loading class Imageloader, when using the glide to replace my writing imageloader, and then the problem came out!!!

The first question: When using your own written imageloader, in order to prevent the item reuse caused by the picture confusion, set the tag as follows code
@Override PublicView GetView (int position, view Convertview, ViewGroupParent) {Viewholder Holder= NULL;if(Convertview== NULL) {Convertview=Minflater.Inflate (R.Layout.Image_list_item,Parent,false); Holder= NewViewholder (); Holder.ImageView=(ImageView) Convertview.Findviewbyid (R.Id.image); Convertview.Settag (holder); }Else{Holder=(Viewholder) Convertview.Gettag (); } ImageView ImageView=Holder.ImageView; FinalString Tag =(String) ImageView.Gettag (); FinalStringUri=GetItem (position);if(!Uri.equals(Tag)) {ImageView.Setimagedrawable (mdefaultbitmapdrawable); }if(Misgridviewidle&&Mcangetbitmapfromnetwork) {ImageView.Settag (URI); Mimageloader.Bindbitmap (URI, ImageView, Mimagewidth, mimagewidth); }returnConvertview; }

Use Settag (object), where each image's URL address is used as a tag to prevent image confusion
When using glide to replace Imageloader, the code is as follows:

Public View GetView (int position, View Convertview, ViewGroup parent) {Viewholder holder = null;if (Convertview = = null) {Convertview = Minflater. Inflate(R. Layout. Item_gridview, parent, false);Holder = new Viewholder ();Holder. ImageView= (ImageView) convertview. Findviewbyid(R. ID. Image);Convertview. Settag(holder);} else {holder = (Viewholder) convertview. Gettag();} ImageView ImageView = Holder. ImageView;Final String tag = (string) imageView. Gettag();Final String uri = GetItem (position);if (!uri. Equals(tag)) {ImageView. Setimagedrawable(mdefaultbitmapdrawable);} if (Misgridviewidle && mcangetbitmapfromnetwork) {ImageView. Settag(URI);Glide. with(Getapplicationcontext ()). Load(URI). Placeholder(R. drawable. Image_default). Crossfade(). into(ImageView);Mimageloader. Bindbitmap(URI, ImageView, Mimagewidth, Mimagewidth);} return Convertview;}

Operation result Error: Java.lang.IllegalArgumentException:You must not call Settag () on a view Glide is targeting
Then the code of ImageView set tag is removed and the program runs normally.
But this time yo with a problem, that is, the picture is a disorder.

Second question: delete the ImageView tag when the picture is garbled

Workaround: Use the Settag (Int,object) method to set the tag so that the above two issues are resolved

Public View GetView (int position, View Convertview, ViewGroup parent) {Viewholder holder = null;if (Convertview = = null) {Convertview = Minflater. Inflate(R. Layout. Item_gridview, parent, false);Holder = new Viewholder ();Holder. ImageView= (ImageView) convertview. Findviewbyid(R. ID. Image);Convertview. Settag(holder);} else {holder = (Viewholder) convertview. Gettag();} ImageView ImageView = Holder. ImageView;Final String tag = (string) imageView. Gettag(R. ID. Imageloader_uri);Final String uri = GetItem (position);if (!uri. Equals(tag)) {ImageView. Setimagedrawable(mdefaultbitmapdrawable);} if (Misgridviewidle && mcangetbitmapfromnetwork) {ImageView. Settag(R. ID. Imageloader_uri,uri);Glide. with(Getapplicationcontext ()). Load(URI). Placeholder(R. drawable. Image_default). Crossfade(). into(ImageView);Mimageloader. Bindbitmap(URI, ImageView, Mimagewidth, Mimagewidth);} return Convertview;}

The R.id.imageloader_uri here is the new ids.xml under values:

<?xml version="1.0" encoding="utf-8"?><resources>    <item name="imageloader_uri" type="id"/></resources>

Picture Loading Library glide--Resolve picture Confusion + Unable to set tag

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.