Android Learning-Other-http Network Tools-with Xutils

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.