简体   繁体   中英

Android ProgressDialog Not Working

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();
        }

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM