Skip to content Skip to sidebar Skip to footer

Progress Dialog On Button Click In Android

I am making an android app in which i have to use progress dialog in android.I want to load progress image when i clicked on login button.Actully i am parsing response and i want t

Solution 1:

Yes you can do that like code below and link. http://developer.android.com/reference/android/os/AsyncTask.html

privateclassDownloadFilesTaskextendsAsyncTask<URL, Integer, Long> {
         protected Long doInBackground(URL... urls) {
             int count = urls.length;
             long totalSize = 0;
             for (int i = 0; i < count; i++) {
                 totalSize += Downloader.downloadFile(urls[i]);
                 publishProgress((int) ((i / (float) count) * 100));
             }
             return totalSize;
         }

         protectedvoidonProgressUpdate(Integer... progress) {
             setProgressPercent(progress[0]);
         }

         protectedvoidonPostExecute(Long result) {
             showDialog("Downloaded " + result + " bytes");
         }
     }

Solution 2:

Show dialog box like this

ProgressDialog pd=newProgressDialog(context);
pd.setMessage("Loading..");pd.setTitle("Please wait");
Thread thread=newThread(newRunnable() {
    @Overridepublicvoidrun() {

            //do your parsing;  //But do not update user interface here
            handler1.sendEmptyMessage(1);
    }
});
pd.show();
thread.start();

now handler message and dismiss dialog using handler class

private Handler handler=newHandler(){
    //Handle message here and dismiss dialog box
};

Post a Comment for "Progress Dialog On Button Click In Android"