Trying to Call An Api on Success will get the Data, But on Failure it Dismisses the Dialog and Displays Blank Plage

huangapple 未分类评论46阅读模式
英文:

Trying to Call An Api on Success will get the Data, But on Failure it Dismisses the Dialog and Displays Blank Plage

问题

如何在数据显示失败后再次调用 API 服务失败时将在进度对话框结束后获得空白屏幕

public void setSemesterData() {
    progressDialog = new ProgressDialog(context, R.style.MyAlertDialogStyle);
    progressDialog.setMessage("Loading..Please Wait");
    progressDialog.setIndeterminate(false);
    progressDialog.setCancelable(false);
    progressDialog.show();
    apiService = RetroClient.getApiService();
    Call<SemesterModel> call = apiService.getSemester(id);
    call.enqueue(new Callback<SemesterModel>() {
        @Override
        public void onResponse(Call<SemesterModel> call, Response<SemesterModel> response) {
            progressDialog.dismiss();

            if (response.isSuccessful()) {
                semesterList.clear();
                semesterList.addAll(response.body().getData());
                semesterAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onFailure(Call<SemesterModel> call, Throwable f) {
            progressDialog.dismiss();
        }
    });
}
英文:

How To Call The Api Service Again on failure to Display the data, On Failure Will get A Blank Screen after the Progress Dialog Ends.

public void setSemesterData() {

    progressDialog=new ProgressDialog(context, R.style.MyAlertDialogStyle);
    progressDialog.setMessage(&quot;Loading..Please Wait&quot;);
    progressDialog.setIndeterminate(false);
    progressDialog.setCancelable(false);
    progressDialog.show();
    apiService= RetroClient.getApiService();
    Call&lt;SemesterModel&gt; call=apiService.getSemester(id);
    call.enqueue(new Callback&lt;SemesterModel&gt;() {
        @Override
        public void onResponse(Call&lt;SemesterModel&gt; call, Response&lt;SemesterModel&gt; response) {
            progressDialog.dismiss();


            if(response.isSuccessful())
            {

                semesterList.clear();
                semesterList.addAll(response.body().getData());
                semesterAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onFailure(Call&lt;SemesterModel&gt; call, Throwable f) {
            progressDialog.dismiss();
        }
    });

}

huangapple
  • 本文由 发表于 2020年5月2日 14:05:02
  • 转载请务必保留本文链接:https://java.coder-hub.com/61555176.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定