如何使用重试对话框LoopJ AndroidAsyncHttp

时间:2015-04-01 17:00:41

标签: android android-async-http

我尝试使用一个布尔参数扩展AsyncHttpClient,在true显示对话框和重试连接但我不知道如何访问用户发送的AsyncHttpResponseHandler onfailure事件,我无法显示重试对话框

重新使用扩展AsyncHttpResponseHandler,如下所示:

import org.apache.http.Header;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.View.OnClickListener;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;

public class CuAsyncHttpResponseHandler extends AsyncHttpResponseHandler {

    private CuActivity activity;
    private boolean retry;
    private CuAsyncHttpResponseHandler response;


    public void CuAsyncHttpResponseHandler(CuActivity activity) {
        this.activity = activity;
        this.retry = false;
        this.response = this;

    }

    public CuAsyncHttpResponseHandler(CuActivity activity, boolean retry) {
        this.activity = activity;
        this.retry = retry;
        this.response = this;

    }


    public void onFailure(int statusCode, Header[] headers,
            byte[] errorResponse, Throwable e) {
        if (this.retry == true) {
            final CuDialogRetry cdd = new CuDialogRetry(activity, null, true);
            cdd.getWindow().setBackgroundDrawable(
                    new ColorDrawable(Color.TRANSPARENT));

            cdd.show();
            cdd.getretryButton().setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    response.onStart();
                    cdd.dismiss();

                }

            });
        }

    }

    @Override
    public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {

    }
}

但是onstart不重启请求(因为它是用于响应而无权访问重试客户端发送请求

0 个答案:

没有答案