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