Android error: Incorrect ListView loading _ incorrect ListView image,

Source: Internet
Author: User

Android error: Incorrect ListView loading _ incorrect ListView image,

When the ListView loads an item, the images in multiple items will be misplaced.

For example, the pictures of the same person are messy.



I found a figure to explain the cause of the problem.

The problem is that convertView is reused. When convertView is reused, seven records are displayed on the first screen, and getView is called seven times. Seven convertviews are created,

When Item1 draws a screen and Item8 enters the screen, no new view instance is created for Item8. Item8 reuse the view created at Item1,

In Item8, the data of Item8 is refreshed, but the code is written in this way at the beginning. The intention is not to load the Avatar when it is empty, which can save resources.

String avatarUrl = user.getAvatar();if (avatarUrl!=null&&!avatarUrl.equals("")) {ImageLoader.getInstance().displayImage(avatarUrl, viewHolder.userLogo,ActivityUtil.getOptions(R.drawable.user_icon_default_main));}
If the avatar of item8 is an empty string, no value is assigned. As a result, item8 displays the avatar of item1, and so on, the original convertView image is displayed, which leads to misplacement of the image.

So I changed it to the following:

// Avatar String avatarUrl = null; if (user. getAvatar ()! = Null) {avatarUrl = user. getAvatar ();} ImageLoader. getInstance (). displayImage (avatarUrl, viewHolder. userLogo, ActivityUtil. getOptions (R. drawable. user_icon_default_main ));
Regardless of whether the Avatar is not empty, load it. Replace the original image of the reused convertView.



Author: jason0539

Blog: http://blog.csdn.net/jason0539 (reprinted please explain the source)

We recommend that you scan the QR code to follow the public account and look at different things.




Related Article

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.