0
我的ProgressDialog在調用retrofit enqueue方法並將數據添加到領域時變爲停止。唯一的問題是progressdialog循環停止並且沒有錯誤。這是我的代碼。顯示ProgressDialog,同時獲取數據並將數據添加到領域db
private void DownloadQuestions(final String chapterId){
final Call<Questions> questionCall = MainApi.createService(MainService.class).
getQuestionsByChapterId(chapterId);
Log.d("Package_Name", getApplicationContext().getPackageName());
pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#272E3E"));
pDialog.setTitleText("Downloading");
pDialog.show();
questionCall.enqueue(new Callback<Questions>() {
@Override
public void onResponse(Call<Questions> call, Response<Questions> response) {
questions.addAll(response.body().getQuestions());
for (Question ques : questions) {
realm.beginTransaction();
QuestionRealm questionRealm = realm.createObject(QuestionRealm.class);
questionRealm.setChapter_id(ques.getChapter_id());
questionRealm.setQuestion_type_id(ques.getQuestion_type_id());
questionRealm.setQuestion(ques.getQuestion());
questionRealm.setHint1(ques.getHint1());
questionRealm.setHint2(ques.getHint2());
questionRealm.setHint3(ques.getHint3());
questionRealm.setHint4(ques.getHint4());
questionRealm.setAnswer(ques.getAnswer());
questionRealm.setYear(ques.getYear());
realm.commitTransaction();
}
pDialog.dismissWithAnimation();
Toast.makeText(getApplicationContext(), " Questions downloaded", Toast.LENGTH_SHORT).show();
quesDownload.setVisibility(View.GONE);
chapCheckBox.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(Call<Questions> call, Throwable t) {
}
});
}
的題數以上400雖然我用的處理程序,即progressdialog仍然來自停止循環,當所有數據添加到境界解僱。我需要解決什麼問題?提前致謝。