我正在使用翻新库。在调用回调成功方法之前,如何使用Progressbar?
public void getMovies() {
MovieClient.getWeather().movies(MovieClient.getRandomMovie(), new Callback<MovieRequest>() {
@Override
public void success(MovieRequest movieRequest, Response response) {
Picasso.with(getApplicationContext()).load(movieRequest.getPoster()).into(image);
}
@Override
public void failure(RetrofitError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
最佳答案
您可以通过以下方式使用它:
public void getMovies() {
ProgressDialog mProgressDialog = new ProgressDialog(this);
mProgressDialog.setIndeterminate(true);
mProgressDialog.setMessage("Loading...");
mProgressDialog.show();
MovieClient.getWeather().movies(MovieClient.getRandomMovie(), new Callback<MovieRequest>() {
@Override
public void success(MovieRequest movieRequest, Response response) {
Picasso.with(getApplicationContext()).load(movieRequest.getPoster()).into(image);
if (mProgressDialog.isShowing())
mProgressDialog.dismiss();
}
@Override
public void failure(RetrofitError error) {
if (mProgressDialog.isShowing())
mProgressDialog.dismiss();
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}