callback function for Android interface

Source: Internet
Author: User

Instance code:

(New Onhttplistener () {@Overridepublic void OnStart () {//TODO auto-generated method Stubsuper.onstart ();} @Overridepublic void onprogress (int mprogress, String message) {//TODO auto-generated method Stubsuper.onprogress ( mprogress, message);} @Overridepublic void Onsuccess (boolean status, int resultcode, String message,string data) {//TODO auto-generated method stub} @Overridepublic void Onfail (Exception e, String message) {//TODO auto-generated method stub} @Overridepublic void OnF Inish () {//TODO auto-generated method Stubsuper.onfinish ();}});

Development often encounter this kind of code, looks very mysterious, onsuccess (), Onfail two method overloads, other methods need to call on their own, in fact very simple, not nonsense, directly on the code:

/** * Process Control start and end callback function * @author Lanyan * */public Abstract interface Onprocesslistener extends Baselistener {/** * start task */vo ID OnStart ();/** * Task End */void onfinish ();}

Progress control:

/** * Progress Control * @author Lanyan * */public abstract class Onprogresslistener implements onprocesslistener{/** * progress bar Display control * @pa Ram mprogress * @param message */public abstract void onprogress (int mprogress,string message); @Overridepublic void OnStar T () {//Todo auto-generated method stub} @Overridepublic void OnFinish () {//Todo auto-generated method stub}

HTT Request:

/** * HTTP Access Progress control * @author Lanyan * */public abstract class Onhttplistener extends onprogresslistener{@Overridepublic void OnProgress (int mprogress, String message) {//TODO auto-generated Method stub}/** * Request failed callback function, return exception information and status code * @param e * @par AM message */public abstract void Onfail (Exception e,string message);/** * Request successful callback function, return response data * @param status * @param messag E * @param data * @param resultcode */public abstract void onsuccess (Boolean status,int resultcode,string message,string D ATA);}

Test class:

public class Test  {public static void main (string[] args) {gethttpdata (httptype.post, URL, parmas, new Onhttplistener () {/* @Overridepublic void OnStart () {//TODO auto-generated method Stubsuper.onstart ();} */@Overridepublic void onsuccess (boolean status, int resultcode, String message,string data) {//TODO auto-generated Metho  D stub} @Overridepublic void Onfail (Exception e, String message) {//TODO auto-generated method stub}/* @Overridepublic void OnFinish () {//TODO auto-generated method Stubsuper.onfinish ();} */});} public static void Gethttpdata (String type,string url,namevaluepair Parmas,onhttplistener listener) {}public enum Httptype{get,post,defult}}



callback function for Android interface

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.