Android ProgressDialog 不工作
该代码不起作用。加载屏幕不显示,但是如果我取出 http.load() ,它就可以正常工作。
Context ctx = v.getContext();
dialog = ProgressDialog.show(ctx, "Login", "Logging in...");
http.load();
http 代码:
try
{
HttpClient hc = new DefaultHttpClient();
HttpPost post = newHttpPost("http://www.example.com/");
HttpResponse rp = hc.execute(post);
if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
result = EntityUtils.toString(rp.getEntity());
}
}catch(IOException e){
e.printStackTrace();
}
}
This code isn't working. The loading screen doesn't show, however if I take out the http.load() it works fine.
Context ctx = v.getContext();
dialog = ProgressDialog.show(ctx, "Login", "Logging in...");
http.load();
http code:
try
{
HttpClient hc = new DefaultHttpClient();
HttpPost post = newHttpPost("http://www.example.com/");
HttpResponse rp = hc.execute(post);
if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
result = EntityUtils.toString(rp.getEntity());
}
}catch(IOException e){
e.printStackTrace();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您从 UI 线程调用
http.load()
并且它会被阻塞,直到该调用完成。您应该使用 AsyncTask 。That's because you're calling
http.load()
from UI thread and it gets blocked until this call completes. You should use AsyncTask for that.