How to add ProgressDialog

前端 未结 4 1651
后悔当初
后悔当初 2020-12-12 04:20

I am downloading a file from dropbox which is taking a few seconds. I want to add a ProgressDialog for the download but I don\'t know how to do that.

         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 04:53

    Use this simple code @sachin

    public class DownloadFile extends AsyncTask {
    
        Home home;
        ProgressDialog dialog = null;
    
        public DownloadFile(Home home) {
            // TODO Auto-generated constructor stub
            this.home = home;
        }
    
        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub
            //Call hare method for download
            return null;
        }
    
        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
             dialog.dismiss();  
    
        }
    
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
             dialog = ProgressDialog.show(home, "Downloading......", "", true);
        }
    
    }
    

提交回复
热议问题