Android's ListView Optimizer

Source: Internet
Author: User

1 Importjava.util.List;2 3 ImportCOM.EXAMPLE.CONTENTPROVIDER.R;4 ImportCom.example.entity.ImagePath;5 ImportCom.example.util.Util;6 7 ImportAndroid.content.Context;8 ImportAndroid.view.LayoutInflater;9 ImportAndroid.view.View;Ten ImportAndroid.view.ViewGroup; One ImportAndroid.widget.BaseAdapter; A ImportAndroid.widget.ImageView; - ImportAndroid.widget.TextView; -  the  Public classMybaseadapterextendsBaseadapter { -     PrivateList<imagepath>imagepaths; - context context; -      +      PublicMybaseadapter (list<imagepath>list, Context context) { -         Super(); +          This. imagepaths =list; A          This. Context =context; at     } -  - @Override -      Public intGetCount () { -         //TODO auto-generated Method Stub -         returnimagepaths.size (); in     } -  to @Override +      PublicObject GetItem (intarg0) { -         //TODO auto-generated Method Stub the         returnImagepaths.get (arg0); *     } $ Panax Notoginseng @Override -      Public LongGetitemid (intarg0) { the         //TODO auto-generated Method Stub +         returnarg0; A     } the  + @Override -      PublicView GetView (intarg0, View arg1, ViewGroup arg2) { $MyView MyView =NULL; $ view view; -         //Arg1 executes the code if NULL, and the If judgment is to optimize the list: If Arg1 is null, the layout is cached in Arg1, and the MyView object is created -         //Store the MyView object in the view! When Arg1 is not empty, the MyView object in the view and the view in the cache are taken out the         if(Arg1 = =NULL){ -             //instantiating a MyView objectWuyiMyView =NewMyView (); the             //Get Layoutinflater Object -Layoutinflater Inflater =Layoutinflater.from (context); Wu             //get the layout of item in a ListView by Inflater -View = Inflater.inflate (R.layout.mybaseadapter,NULL); About             //gets the component of the item layout $Myview.imageview =(ImageView) View.findviewbyid (r.id.id_image); -Myview.textname =(TextView) View.findviewbyid (r.id.id_textname); -Myview.textnum =(TextView) View.findviewbyid (r.id.id_textnum); -             //save a MyView object into view A View.settag (myView); +}Else{ the             //if arg1 is not NULL, assign arg1 to the view -View =arg1; $             //take out the MyView object that is stored in the view theMyView Myviewtag =(MyView) View.gettag (); the         } the MyView.textName.setText (Imagepaths.get (arg0). Getpakagepath ()); theMyView.textNum.setText ("Total" +imagepaths.get (arg0). Getlistpth (). Size () + "Zhang"); -MyView.imageView.setImageBitmap (Util.getbitmapbypath (Imagepaths.get (arg0). Getlistpth (). Get (0), 86,86)); in         returnview; the     } the  About } the     classmyview{ the TextView textname; the TextView Textnum; + ImageView ImageView; -}

Only touch Android, in the slowly self-study! Subsequent updates

Android's ListView Optimizer

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.