i using ion library download json object response php web services. using way :
ion.with(getactivity()) .load("http://amd.com/loginservice.php") .progressbar(progressbar).progress(new progresscallback() { @override public void onprogress(long downloaded, long total) { int mprogress = (int) (100 * downloaded / total); progressbar.setprogress(mprogress); } }) .setmultipartparameter("fb_id", id) .setmultipartparameter("fb_token", accesstoken.getcurrentaccesstoken().tostring()) .asjsonobject() .setcallback(new futurecallback<jsonobject>() { @override public void oncompleted(exception e, jsonobject result) { if (result == null) { toast.maketext(getactivity(), "error", toast.length_short).show(); progressbar.setvisibility(view.gone); } else { log.v("ionresult", result.tostring()); progressbar.setvisibility(view.gone); } } }); now want ask 2 questions:
how can show "please wait" , progress bar in manner? progress bar should appear , disappear when response of server has been achieved.
how parse json getting in response? have logged results
log.v("ionresult", result.tostring());
and can see response, how can use , parse , items want?
please help, know basic question, beginner in android, please me improve. thanks.
i started using ion recently, i'm not sure if best way (please, if know, leave comment here!).
so, i'm using callbacks return value class.
public interface responsecallback { public void onsuccess(string result); public void onerror(string result); } one example in code:
public void getchats(final context context, final string url,final responsecallback responsecallback) { ion.with(context) .load(url) .asstring() .setcallback(new futurecallback<string>() { @override public void oncompleted(exception e, string result) { if (e != null) { if (responsecallback != null) { responsecallback.onerror(e.tostring()); } toast.maketext(context, "error loading chat list.", toast.length_short); return; } if (responsecallback != null) { responsecallback.onsuccess(result); } } }); } so, when call getchats(), implement responsecallback methods. hope helps, think there's better way that.
Comments
Post a Comment