ListView Display in Android and its optimization benefits

Source: Internet
Author: User

Display effect:

The middle item entry is able to swipe up and down.

Code implementation:

1 @Override2          PublicView GetView (intposition, View Convertview, ViewGroup parent) {3 4 Viewholder Holder;5             if(Convertview = =NULL) {6Convertview = View.inflate (cleancacheactivity. This,7R.layout.list_item_cacheinfo,NULL);8Holder =NewViewholder ();9 TenHolder.tvname =(TextView) Convertview One . Findviewbyid (r.id.tv_name); AHolder.tvcache =(TextView) Convertview - . Findviewbyid (R.id.tv_cache); -Holder.ivicon =(ImageView) Convertview the . Findviewbyid (R.id.iv_icon); -Holder.ivclean =(ImageView) Convertview - . Findviewbyid (R.id.iv_clean); -  + Convertview.settag (holder); -}Else { +Holder =(Viewholder) Convertview.gettag (); A             } at             FinalCacheinfo info =GetItem (position); - Holder.tvName.setText (info.name); -Holder.ivIcon.setImageDrawable (Info.icon);
26//...
Convertview return;
28}

1     //ListView Property Encapsulation2     classViewholder {3          PublicTextView Tvname;4          PublicTextView Tvcache;5          PublicImageView Ivicon;6          PublicImageView Ivclean;7     }8 9     //Cache Information EncapsulationTen     classCacheinfo { One          PublicString name; A          PublicString PackageName; -          Publicdrawable icon; -          Public LongcacheSize; the}

Optimization Features:

1.

Reduce the number of Findviewbyid

2.

Reduce the number of objects created (Holder = new viewholder ();)

3.

achieve paging load, save consumption.

ListView Display in Android and its optimization benefits

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.