This example describes the ListView item layout optimization techniques in Android. Share to everyone for your reference, specific as follows:
Have never known ListView have a variety of layout optimization methods, can only be realized by hiding, they also know that efficiency is certainly very low, but also do not know what method, these days and check some information, and then know that in fact Google has helped us to think about the optimization program.
Suppose your ListView item has three possible layout styles: It's simple to display a line of words, left, center, and right.
Then we can rewrite two methods in Baseadapter:
private static final int type_left = 0;
private static final int type_center = 1;
private static final int type_right = 2;
@Override public int Getviewtypecount () {return 3;
//If we have a list of data, the bean inside has an attribute (type) that indicates which layout the item should use.
@Override public int Getitemviewtype (int position) {return list.get (position). type; //Then we can do this in our GetView method @Override public View getview (int position, View Convertview, viewgroup parent) {int type
= Getitemviewtype (position);
Viewholdleft Holdleft;
Viewholdcenter Holdcenter;
Viewholdright Holdright;
if (Convertview = = null) {switch (type) {case type_left:holdleft = new Viewholdleft ();
Convertview = xxxxxx//like ordinary Holdleft.textview = xxxxxx//like ordinary HoldLeft.textView.setText ("Holdleft");
Convertview.settag (Holdleft);
Break
Case type_center:holdcenter = new Viewholdcenter (); Convertview = xxxxxx//like ordinary Holdcenter.textview = xxxxxx//as normal HoldCenter.textView.setTexT ("Holdcenter");
Convertview.settag (Holdcenter);
Break
Case type_right:holdright = new Viewholdright ();
Convertview = xxxxxx//like ordinary Holdright.textview = xxxxxx//like ordinary HoldRight.textView.setText ("holdright");
Convertview.settag (Holdright);
Break
Default:break;
} else {switch (type) {case type_left:holdleft = (viewholdleft) convertview.gettag ();
HoldLeft.textView.setText ("Holdleft");
Break
Case type_center:holdcenter = (viewholdcenter) convertview.gettag ();
HoldCenter.textView.setText ("Holdcenter");
Break
Case type_right:holdright = (viewholdright) convertview.gettag ();
HoldRight.textView.setText ("Holdright");
Break
Default:break;
} return Convertview;
private static class Viewholdleft {private TextView TextView;
private static class Viewholdcenter {private TextView TextView; private static class Viewholdright {private TExtview TextView; }
Gogle is still very human.
I hope this article will help you with the Android program.