Hi,
How to get progress dialogue when the application is fetching data from web in android?
            Asked
            
        
        
            Active
            
        
            Viewed 412 times
        
    0
            
            
         
    
    
        user996550
        
- 21
- 2
- 
                    here you can see http://stackoverflow.com/q/3028306/626481 – Hanry Oct 15 '11 at 06:24
- 
                    or http://www.hassanpur.com/blog/2011/04/android-development-downloading-a-file-from-the-web/ – Hanry Oct 15 '11 at 06:26
2 Answers
0
            
            
        you can use the 'AsyncTask' process the download. and it has a method onProgressUpdate(Progress...). in this method you can diaplay the progress
 
    
    
        Devin Burke
        
- 13,642
- 12
- 55
- 82
 
    
    
        tesla1984
        
- 541
- 2
- 8
0
            
            
        public class SimpleWebGrab extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        grabURL("http://android.com");
    }
    public void grabURL(String url) {
        new GrabURL().execute(url);
    }
    private class GrabURL extends AsyncTask<String, Void, Void> {
        private final HttpClient Client = new DefaultHttpClient();
        private String Content;
        private String Error = null;
        private ProgressDialog Dialog = new ProgressDialog(SimpleWebGrab.this);
        protected void onPreExecute() {
            Dialog.setMessage("Downloading source..");
            Dialog.show();
        }
        protected Void doInBackground(String... urls) {
            try {
                HttpGet httpget = new HttpGet(urls[0]);
                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                Content = Client.execute(httpget, responseHandler);
            } catch (ClientProtocolException e) {
                Error = e.getMessage();
                cancel(true);
            } catch (IOException e) {
                Error = e.getMessage();
                cancel(true);
            }
            return null;
        }
        protected void onPostExecute(Void unused) {
            Dialog.dismiss();
            if (Error != null) {
                Toast.makeText(SimpleWebGrab.this, Error, Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(SimpleWebGrab.this, "Source: " + Content, Toast.LENGTH_LONG).show();
            }
        }
    }
}
 
    
    
        Android
        
- 2,383
- 1
- 26
- 44