如何使用齐射进行网络操作时显示ProgressDialog

编程入门 行业动态 更新时间:2024-10-28 03:27:56
本文介绍了如何使用齐射进行网络操作时显示ProgressDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Android应用程序进行Woking,我非常有兴趣使用 volley 库来执行网络http调用。

I am Woking on an android application where I am very interested to use volley library to perform the network http calls.

但是我的问题我发现这个库在不同的后台线程中进行操作然后如何在http时显示 ProgressDialog 请求开始执行,然后在执行后将其解除。

But my question I found that this library do operations in different background thread then How I can showProgressDialog when http request start to execute then later dismiss it once it has executed.

RequestQueue rq = Volley.newRequestQueue(this); StringRequest postReq = new StringRequest(Request.Method.POST, "httpbin/post", new Response.Listener<String>() { @Override public void onResponse(String response) { tv.setText(response); // We set the response data in the TextView } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { System.out.println("Error ["+error+"]"); } });

提前致谢。

推荐答案

这很直接。在队列中添加请求对象后启动进度对话框。

It's pretty straight forward. Start the progress dialog once you add the request object in the queue.

//add the request to the queue rq.add(request); //initialize the progress dialog and show it progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("Fetching The File...."); progressDialog.show();

然后在收到服务器的回复后关闭对话框。

Then dismiss the dialog once you have received the response from the server.

StringRequest postReq = new StringRequest(Request.Method.POST, "httpbin/post", new Response.Listener<String>() { @Override public void onResponse(String response) { tv.setText(response); // We set the response data in the TextView progressDialog.dismiss(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("Volly Error","Error: "+error.getLocalizedMessage()); progressDialog.dismiss(); } });

更多推荐

如何使用齐射进行网络操作时显示ProgressDialog

本文发布于:2023-11-16 14:19:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   操作   网络   ProgressDialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!