android - 无法关闭进度默认进度对话框andorid
问题描述
我是新手,Android
我自己学习。我正在尝试实现android的默认值ProgressDialog
,但问题是,当我dismiss()
在网络响应中调用方法时,它并没有消失。
private void loadData() {
// rooms.clear();
final ProgressDialog progress = new ProgressDialog(getContext());
progress.show(getContext(),"Loading..","Please wait");
progress.show();
RequestQueue requestQueue = Volley.newRequestQueue(context);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, Api.getAllPost, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
progress.dismiss();
try {
JSONArray array = response.getJSONArray("data");
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
Room room = new Gson().fromJson(object.toString(),Room.class);
// Toast.makeText(context, "Sucess", Toast.LENGTH_SHORT).show();
rooms.add(room);
}
roomAdapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progress.dismiss();
Toast.makeText(context, "Server error", Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(jsonObjectRequest);
}
我在这个网站上尝试了其他解决方案,但没有奏效。请有人帮助我。
解决方案
首先不要使用ProgressDialog
,因为它现在已被弃用。但是对于您的解决方案,请尝试替换您的代码:
final ProgressDialog progress = new ProgressDialog(getContext());
progress.show(getContext(),"Loading..","Please wait");
progress.show();
通过以下代码:
final ProgressDialog progress = new ProgressDialog(getContext());
progress.setTitle("Loading..");
progress.setMessage("Please wait");
progress.setCancelable(false);
progress.show();
它应该工作:)
推荐阅读
- python - python中-5和小于-5的数字有什么区别
- php - 如何在 octobercms 中上传多张图片?
- r - ggplot2, geom_line inside loop 只显示一行
- mysql - 将一张桌子连接到多张桌子
- python - Django 看不到静态文件
- apache-kafka - 我正在使用 Kafka Producer Api 将文件中的消息写入 kafka 主题,但 kafka 主题的日志显示为空?
- json - 仅从 Array 中检索值
- javascript - 如何从谷歌 api 文档中的数据中制作 vuex getter?
- java - 使用 thymeleaf 时使用多个页眉、页脚
- reactjs - React:使用 React-router 实现 Redux 时遇到问题