实例代码:
(new OnHttpListener() { @Override public void onStart() { // TODO Auto-generated method stub super.onStart(); } @Override public void onProgress(int mProgress, String message) { // TODO Auto-generated method stub super.onProgress(mProgress, message); } @Override public void onSuccess(boolean status, int resultCode, String message, String data) { // TODO Auto-generated method stub } @Override public void onFail(Exception e, String message) { // TODO Auto-generated method stub } @Override public void onFinish() { // TODO Auto-generated method stub super.onFinish(); } });
/** * 流程控制开始和结束回调函数 * @author LanYan * */ public abstract interface OnProcessListener extends BaseListener { /** * 开始任务 */ void onStart(); /** * 任务结束 */ void onFinish(); }
/** * 进度控制 * @author LanYan * */ public abstract class OnProgressListener implements OnProcessListener{ /** * 进度条的显示控制 * @param mProgress * @param message */ public abstract void onProgress(int mProgress,String message); @Override public void onStart() { // TODO Auto-generated method stub } @Override public void onFinish() { // TODO Auto-generated method stub }
/** * HTTP访问进度控制 * @author LanYan * */ public abstract class OnHttpListener extends OnProgressListener{ @Override public void onProgress(int mProgress, String message) { // TODO Auto-generated method stub } /** * 请求失败回调函数,返回异常信息和状态码 * @param e * @param message */ public abstract void onFail(Exception e,String message); /** * 请求成功回调函数,返回响应数据 * @param status * @param message * @param data * @param resultCode */ public abstract void onSuccess(boolean status,int resultCode,String message,String data); }
public class Test { public static void main(String[] args) { getHttpData(HttpType.post, url, parmas, new OnHttpListener() { /*@Override public void onStart() { // TODO Auto-generated method stub super.onStart(); }*/ @Override public void onSuccess(boolean status, int resultCode, String message, String data) { // TODO Auto-generated method stub } @Override public void onFail(Exception e, String message) { // TODO Auto-generated method stub } /*@Override public void onFinish() { // TODO Auto-generated method stub super.onFinish(); }*/ }); } public static void getHttpData(String type,String url,NameValuePair parmas,OnHttpListener listener){ } public enum HttpType{ get,post,defult } }
原文地址:http://blog.csdn.net/anddroid_lanyan/article/details/45844031