Today, follow the methods provided by Apidemos to achieve the slow loading effect.
Simple Implementation Method:
To implement Listview.onscrolllistener, the monitor hears gesture swipe, when in a scrolling state, the newly displayed items are set to loading, and the actual data is loaded when you leave the screen.
When setting data, use the Getfirstvisibleposition property to calculate the number of item that should be loaded.
This small demo should be considered as the basis for learning Android Asynctask asynchronous loading.
Main.java
Import Android.app.listactivity;import Android.content.context;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Android.widget.abslistview;import Android.widget.baseadapter;import Android.widget.listview;import Android.widget.textview;import com.example.testmyviewslistsactivateitems.r;/** * * @author Administrator imitation effect slow Loading Apidemos--Views-lists-slow Adapter */public class Main extends Listactivity {private Boolean mbusy = False;@o verrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setlistadapter (new Slowadapter (this));//Set selection mode to Radio Getlistview (). Setchoicemode (Listview.choice_mode_single);// First load settings check Itemsgetlistview (). setitemchecked (0, true); Getlistview (). Setonscrolllistener (New Onscrolllistener ());} Protected class Onscrolllistener implements Listview.onscrolllistener {@Overridepublic void onscrollstatechanged ( Abslistview view, int scrollstate) {switch (ScrollstaTE) {//the view is not scrolling.case OnScrollListener.SCROLL_STATE_IDLE:mBusy = false;int first = View.getfirstvisiblepo Sition (); int count = View.getchildcount (); for (int i = 0; i < count; i++) {TextView t = (TextView) view.getchildat (i); I F (t.gettag () = null) {T.settext (Mstrings[first + i]); T.settag (null);}} break;//the user is scrolling using touch, and their finger are still on the Screencase Onscrolllistener.scroll_state_touc H_scroll:mbusy = True;break; The user had previously been scrolling using touch and had performed a fling. The animation is now coasting to a stopcase OnScrollListener.SCROLL_STATE_FLING:mBusy = True;break;}} @Overridepublic void Onscroll (abslistview view, int firstvisibleitem,int visibleitemcount, int totalitemcount) {}}@ overrideprotected void Onlistitemclick (ListView l, View v, int position, long id) {Getlistview (). setitemchecked (position , true);} Custom adapter Private class Slowadapter extends Baseadapter {private Layoutinflater minflater;public SlowaDapter (Context context) {Minflater = (layoutinflater) context.getsystemservice (context.layout_inflater_service);} @Overridepublic int GetCount () {return mstrings.length;} @Overridepublic Object getItem (int position) {return position;} @Overridepublic long Getitemid (int position) {return position;} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {TextView text;if (Convertview = = null) {TE XT = (TextView) minflater.inflate (R.layout.main, NULL, FALSE);} else {text = (TextView) Convertview;} if (!mbusy) {text.settext (mstrings[position]); Text.settag (null);} else {text.settext ("Loading ..."); Text.settag ( this);} return text;}} Datapublic static final string[] Mstrings = {"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "abondance", "Ac Kawi "," Acorn "," Adelost "," Affidelice au Chablis "," Afuega ' L Pitu "," Airag "," Airedale "," Aisy cendre "," Allgauer Emmental Er "," Alverca "," Ambert "," American Cheese "," Ami du Chambertin "," Anejo Enchilado "," Anneau du Vic-bilh "," ANthoriro "," Appenzell "," Vacherin-fribourgeois "," Valencay "," Vasterbottenost "," Venaco "," Vendomois "," Vieux Corse "," Vignotte "," Vulscombe "," Waimata farmhouse Blue "," Washed Rind Cheese (Australian) "," Waterloo "," Weichkaese "," Wellington "," Wensleydale "," White Stilton "," Whitestone Farmhouse "," Wigmore "," Woodside Cabecou "," Xanadu "," Xynotyro " , "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue", "Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano " };}
Code download