A project was written at the time, not very perfect, basically can use
Packageorg.excsoft.g;ImportJava.lang.reflect.ParameterizedType;Importorg.excsoftj.m.msg;ImportAndroid.app.AlertDialog;ImportAndroid.app.ProgressDialog;ImportAndroid.content.Context;ImportAndroid.content.DialogInterface;ImportAndroid.os.Handler;ImportAndroid.os.Message;Importcom.lidroid.xutils.exception.HttpException;ImportCom.lidroid.xutils.http.ResponseInfo;ImportCom.lidroid.xutils.http.callback.RequestCallBack;ImportCom.thoughtworks.xstream.XStream;ImportCom.thoughtworks.xstream.io.xml.DomDriver; Public classMyrequestcallback<t>extendsRequestcallback<t>{ Booleanshowflag=false; Booleancancelflag=false; Public Booleansuccess=false; PublicMSG returnmsg=NewMSG (); PrivateProgressDialog PD; Privatecontext Context; PrivateHandler Mhandler; BooleanCancanel=false; Java.lang.Class CLS; intdelayedtime=500; String msg11; //private HttpHandler hddd; PublicMyrequestcallback (Context context,Booleancancanel,java.lang.class cls,string msg11) { Super. OnStart (); This. context=context; This. cancanel=Cancanel; This. cls=CLS; This. msg11=msg11; } PublicMyrequestcallback (Context context,BooleanCancanel,java.lang.class cls,string msg11,intdelayedtime) { Super. OnStart (); This. context=context; This. cancanel=Cancanel; This. cls=CLS; This. msg11=msg11; This. delayedtime=Delayedtime; } Public voidOnStart () {Showflag=true; Cancelflag=false; Message Message=NewMessage (); Message.what=1; Mhandler=NewHandler () { Public voidhandlemessage (Message msg) {if(showflag) {PD=progressdialog.show (Context, "", Msg11,true, Cancanel); Pd.setoncancellistener (NewDialoginterface.oncancellistener () { Public voidonCancel (Dialoginterface Dialog) {Cancelflag=true; } }); } Super. Handlemessage (msg); } }; Mhandler.sendmessagedelayed (Message,delayedtime); } Public voidOnsuccess (responseinfo<t>responseinfo) { Try{Showflag=false; if(pd!=NULL) {Pd.dismiss (); } mhandler.removemessages (1); if(!Cancelflag) { FinalXStream XStream =NewXStream (Newdomdriver ()); Xstream.ignoreunknownelements (); Xstream.alias ("MSG", MSG.class); Xstream.alias ("Item", CLS); String Res=responseinfo.result+ ""; if(Res.indexof ("flag") >0) {returnmsg=(MSG) xstream.fromxml (res); if(Returnmsg.getflag (). Equals ("1") ) {Success=true; }Else{ FinalString sm=RETURNMSG.GETSM (); NewAlertdialog.builder (context). Settitle ("hint"). Setmessage (SM). Setnegativebutton ("OK",NULL). Show (); } }Else{ NewAlertdialog.builder (context). Settitle ("Failed"). Setmessage (Reason: Network unavailable). Setnegativebutton ("OK",NULL). Show (); } } }Catch(Exception e) {NewAlertdialog.builder (context). Settitle ("Failed"). Setmessage (Reason: Network unavailable). Setnegativebutton ("OK",NULL). Show (); } }//@Override//Public void onloading (Long, Long, Boolean isuploading) {//super.onloading (total, Current, isuploading);//if (cancelflag&& (hddd!=null)) {//hddd.stop ();// }// }@Override Public voidonfailure (httpexception error, String msg) {if(pd!=NULL) {Pd.dismiss (); } mhandler.removemessages (1); if(!Cancelflag) { NewAlertdialog.builder (context). Settitle ("Failed"). Setmessage (Reason: Network unavailable). Setnegativebutton ("OK",NULL). Show (); } } }
Android Learning-Other-http Network Tools-with Xutils