Original Address link: Http://stackvoid.com/list-view-optimization-best-practice-android/
I have a blog that teaches you how to improve the situation with Convertview and Viewholder (static), but when the ListView loads a lot of complex layouts and pictures, even with Convertview and Viewholde R,listview or lag, this article discusses how to load complex list_item while ensuring the flow of the ListView.
The core idea is
Listen for the load, load data asynchronously.
The Main method:
-
First judge the current ListView state, only the ListView stop sliding to open the new line loads load data, other states are ignored.
-
Use the Getfirstvisibleposition and Getlastvisibleposition methods to display item.
-
Time consuming tasks must not be done in the GetView method, preferably asynchronously.
The specific code is as follows:
1 //1. Judging the ListView State2 Abslistview.Onscrolllistener Onscrolllistener = New Abslistview.Onscrolllistener() {//ListView3 //Touch Events4 5 Public void onscroll(Abslistview View, int Firstvisibleitem, int VisibleItemCount, int Totalitemcount) {6 }7 8 Public void onscrollstatechanged(Abslistview View, int scrollstate) {9 Switch (scrollstate) {Ten Case Abslistview.Onscrolllistener.scroll_state_fling://Sliding State One Threadflag = false; A Break; - Case Abslistview.Onscrolllistener.Scroll_state_idle://Stop - Threadflag = true; the Startthread();//Open new thread, load data - Break; - Case Abslistview.Onscrolllistener.Scroll_state_touch_scroll://Touch ListView - Threadflag = false; + Break; - default: + //Toast.maketext (CONTEXTT, "Default", A //Toast.length_short). Show (); at Break; - } - } - };
Believe to do the above three points, you can use the ListView freely, O (∩_∩) o haha ~
Android ListView Optimization Best Practices