Inherit Asynctask, there are three parameters
The meaning of the three parameters is the first one to represent the input parameter, the second is progress, the current progress, and the third is Doinbackground
return value
A parameter is required to pass in the URL, which returns a result if no network is returned empty
Import Java.io.inputstream;import java.util.arraylist;import Java.util.linkedhashmap;import Java.util.List;import Mybook.bookinfo;import mybook.httpget;import mybook.jsontest;import Android.os.asynctask;import android.util.Log; Import Android.widget.linearlayout;import Android.widget.listview;import Hdu.m12306.zzy.*;import Hdu.m12306.zzy.listview.myadapter2;public class MyTask extends Asynctask<string, void,string > {private LinearLa Yout Li; Private ListView ListView; Private Myadapter2 Myadapter; Private InputStream in; Private list<linkedhashmap> Data_set; Private HttpGet httpget;//need a parameter to pass in the URL, return a result results, if there is no network return NULL//three parameters meaning is the first to represent the input parameters, the second is progress, the third is a doinbackground return value public mytask (ListView listview,myadapter2 adapter,httpget httpget) {this.listview=listview;this.myadapter= Adapter;//this.in=in;this.httpget=httpget;new arraylist<linkedhashmap> ();} @Overrideprotected String Doinbackground (string...urls) {//TODO auto-generated method StubstriNg Response=null;//urls is a string array, string Geturl=new string (), and for (string url:urls) Geturl+=url; LOG.E ("Geturl", Geturl);//httpget http=new HttpGet (geturl,in);//http.init (); InputStream myin=httpget.get_in ();// Read to the end of the file, there will be a problem//certificate file read end Response=httpget.get_reponse (Myin); return response;} protected void OnPostExecute (String result) {//doinbakcground Returns the result//This inside with the new Uiif (result!=null) {jsontest json=new Jsontest (result); Json.init (); Data_set=json.get_data (); Myadapter.set_dataset (Data_set); Listview.setadapter (Myadapter);}} }
Update in the following code
public void On_fresh (final View v) { mytask task=new mytask (listview,myadapter,http); LOG.E ("Onfresh", url); String []params=new String[]{url}; Task.execute (params); }