public void onClick() {
new FetchTask(context).execute(null);
}
public class FetchTask extends AsyncTask<Object, Object, Object > {
private ProgressDialog dlg;
private Context ctx;
public FetchTask(Context context) {
ctx = context;
}
@Override
protected void onPreExecute() {
dlg = new ProgressDialog(ctx);
dlg.setMessage("Loading....");
super.onPreExecute();
}
@Override
protected void onPostExecute(Object result) {
dlg.dismiss();
if ( result instanceof Exception ) {
// show error message
} else {
// display data
}
super.onPostExecute(result);
}
@Override
protected Object doInBackground(Object... params) {
try {
// String rawData = doPost("yourUrl");
// XMLTree data = yourParser.parse(rawData);
// return data;
} catch ( Exception e ) {
return e;
}
}
}