Reputation: 1051
I'm trying to create a loading dialog using an AlertDialog inside a Retrofit call, however this loading dialog is not showing up at all. I want to show it while the call is downloading and setting up the recyclerView. Right now the dialog is not showing up at all, it sets the recyclerView and everything without showing the dialog. I'm not sure if this matters but this is inside a fragment.
This is the full retrofit call
Call<List<Evaluator>> call = apiInterface.getSurveys();
call.enqueue(new Callback<List<Evaluator>>() {
@Override
public void onResponse(Call<List<Evaluator>> call, Response<List<Evaluator>> response) {
if (!response.isSuccessful()) {
//show error toast
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setCancelable(true);
LayoutInflater inflater = getLayoutInflater();
inflater.inflate(R.layout.dialog_loading, null);
AlertDialog dialog = builder.create();
dialog.show();
List<Evaluator> masterItem = response.body();
masterItem.forEach(evaluator -> {
if (!evaluator.getAnswered()) {
surveys.add(new Evaluator(evaluator));
}
});
mAdapter = new SurveyAdapter(surveys);
mRecyclerView.setAdapter(mAdapter);
dialog.dismiss();
}
@Override
public void onFailure(Call<List<Evaluator>> call, Throwable t) {
//show error toast
}
});
Upvotes: 0
Views: 131
Reputation: 967
call dialog.show()
before you call retrofit call.enqueue
. And inside response or failure dismiss the dialog.
And don't forget to dismiss dialog in both onResponse
and onFailure
.
Upvotes: 1