/** * Package Proecssdialog dialog box * */public class Loaddialog extends ProgressDialog {private string title = Progress Dialog;p Rivate String Message = "Load data ....";p ublic Loaddialog (context context, int theme) {Super (context, theme);} /** * Create dialog box with default title and content * @param context */public Loaddialog (context) {super (context); InitDialog ();} /** * Create a dialog box with the specified title and content * @param context * @param title * @param message */public loaddialog (context context,string title,st Ring message) {super (context); if (title! = null) {this.title = title;} if (message! = null) {this.message = message;} InitDialog ();} /** * Initialize the dialog, the default dialog cannot be canceled */public void InitDialog () {settitle (title); setmessage (message); Setprogressstyle ( Progressdialog.style_spinner); setcancelable (false);} /** * Opens the dialog box. Set the callback method, pass the class template that needs to run the business method, the method name and the list of parameters * @param the callback callback method, callback after the dialog box closes, and get the returned data * @param class template running the business method * @param met Hod method name for running business methods * @param params run business method's list */public void execute (Callback callback,class serviceclass,string method,objec T. params) {SUPER.Show (); Serviceaysntask task = new Serviceaysntask (Callback,serviceclass,method); Task.execute (params);} /** * Callback Method interface * */public interface callback{public void GetResult (map map);} /** * Thread class communicating with remote service * @author BDK * Asynctask Asynchronous Task */private class Serviceaysntask extends ASYNCTASK<OBJECT,OBJECT,MAP&G T {Private Class serviceclass;private String method;private Callback callback;public serviceaysntask (Callback Callback, Class serviceclass,string method) {this.callback = Callback;this.serviceclass = Serviceclass;this.method = method;} @Overrideprotected map Doinbackground (Object ... params) {Map Resultmap = null;try {Object obj = serviceclass.newinstance ( );//Create class Template Object class [] Paramtypes = new Class[params.length];for (int i = 0; i < paramtypes.length; i++) {Paramtypes[i] = Params[i].getclass ();} Based on the class template get method M = Serviceclass.getmethod (method, paramtypes); resultmap = (Map) m.invoke (obj, params);} catch (Exception e) {e.printstacktrace ();} LoadDialog.this.cancel (); return resultmap;} @Overrideprotected void OnPostExecute (Map result) {Super.onpostexecute (result); if (result = = null) {Toast.maketext ( LoadDialog.this.getContext (), "Network communication exception", Toast.length_long). Show (); return;} Callback.getresult (result);}}}
Android Request network asynchronous loading