V4 's Compatibility Pack
API
About these 4 commonly used methods.
Code
Layout
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context=". Mainactivity " > <Android.support.v4.widget.SwipeRefreshLayoutAndroid:id= "@+id/swipe"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <ListViewAndroid:id= "@+id/listview"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content" /> </Android.support.v4.widget.SwipeRefreshLayout></Relativelayout>
Mainactivty
@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); ListView=(ListView) Findviewbyid (R.id.listview); Mswipelayout=(swiperefreshlayout) Findviewbyid (r.id.swipe); List=NewArraylist<mytextclass>(); Map<string, string> maps =NewHashmap<string, string>(); Maps.put ("1", "2"); MyHandler=NewMyHandler (); Client=Newmyhttpclient (MyHandler); MyThread=NewMyThread (client, "http://192.168.1.4/json/index.php", Maps,getjson); Myhandler.setthread (MyThread); Myhandler.sethandlerextrahandlemessage (NewMyhandler.handlerextrahandlemessage () {@Override Public voidhandlemessage (Message msg) {Switch(msg.what) { Casegetjson:string StrJson1=(String) msg.obj; Json Json1=NewJson (StrJson1); Try{List=Json1.getmytextclass (); } Catch(jsonexception e) {e.printstacktrace (); } mybaseadapter=NewMybaseadapter (mainactivity. This, list); Listview.setadapter (Mybaseadapter); Break; Caserefresh:string StrJson2=(String) msg.obj; Json Json2=NewJson (StrJson2); //list.clear (); Try{List=Json2.getmytextclass (); } Catch(jsonexception e) {e.printstacktrace (); } if(Mybaseadapter! =NULL) {mybaseadapter.setlist (list); Mybaseadapter.notifydatasetchanged (); } Else{mybaseadapter MyBaseAdapter2=NewMybaseadapter (mainactivity. This, list); Listview.setadapter (MYBASEADAPTER2); } mswipelayout.setrefreshing (false); Break; default: System.out.println ("Other Message"); Break; } Super. Handlemessage (msg); } }); Map<string, string> maps2 =NewHashmap<string, string>(); Maps.put ("1", "2"); Myrefreshlistener Myrefreshlistener=NewMyrefreshlistener (MyHandler, MAPS2, REFRESH); Mswipelayout.setonrefreshlistener (Myrefreshlistener); Mswipelayout.setcolorscheme (Android. R.color.holo_green_dark, Android. R.color.holo_green_light, Android. R.color.holo_orange_light, Android. R.color.holo_red_light); }I'm the dividing line of the king of the land Tiger.
Source code: HTTP://PAN.BAIDU.COM/S/1DD1QX01
ListView Async. Zip