我猜你做了类似以下的事情
AsyncHttpClient client = new AsyncHttpClient();
client.get("https://www.example.com", new AsyncHttpResponseHandler() {
@Override
public void onStart() {
// called before request is started
findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE);
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
// called when response HTTP status is "200 OK"
findViewById(R.id.loadingPanel).setVisibility(View.GONE);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
}
@Override
public void onRetry(int retryNo) {
// called when request is retried
}
});
只需尝试以下操作
boolean showProgress= true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AsyncHttpClient client = new AsyncHttpClient();
client.get("https://www.google.com", new AsyncHttpResponseHandler() {
@Override
public void onStart() {
// called before request is started
//findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(showProgress){
findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE);
}
}
}, 5*1000); // your progress will start after 5 seconds
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
// called when response HTTP status is "200 OK"
//findViewById(R.id.loadingPanel).setVisibility(View.GONE);
showProgress = false;
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
showProgress = false;
}
@Override
public void onRetry(int retryNo) {
// called when request is retried
}
});
}