Android asyncTask Circle dialog box

Today I searched all day, trying to find some sample code or tutorials on how to create a progress flow when a task is executed. The completion time for this task changes accordingly, and there are many patterns that use Thread.sleep (xxxx) to make it circular, but it is inefficient. Here is what I want to do, I want to load a ListView that populates from a web service using JSON after clicking a button. The list is scanned perfectly fine, but loading takes about 5-10 seconds depending on size, so I want to show a circular motion when the user waits. Can someone please share some sample code on how to achieve this?

thank

+5
source share
3 answers

new Load().execute(); to call.

class Load extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            ProgressDialog progDailog = new ProgressDialog(Activity.this);
            progDailog.setMessage("Loading...");
            progDailog.setIndeterminate(false);
            progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progDailog.setCancelable(true);
            progDailog.show();
        }
        @Override
        protected String doInBackground(String... aurl) {
            //do something while spinning circling show
            return null;
        }
        @Override
        protected void onPostExecute(String unused) {
            super.onPostExecute(unused);
            progDailog.dismiss();
        }
    }
+29
source
private class LoadAssync extends AsyncTask<String, Void, Void> {



    protected void onPreExecute() {

        ProgressDialog dialog;
                   dialog.setMessage("Loading...");
    dialog.show();
    }

    protected Void doInBackground(final String... args) {
        // you can do the code here
        return null;


    }

    protected void onPostExecute(final Void unused) {

        if (dialog.isShowing()) {
            dialog.dismiss();
        }

    }
}

u can call assync like this

 LoadAssync mAsyync=new LoadAssync();
 mAsyync.execute(null);
+11
source

You can try the following code,

progDailog = ProgressDialog.show(loginAct,"Process ", "please wait....",true,true);

new Thread ( new Runnable()
{
     public void run()
     {
      // your code goes here
     }
}).start();

 Handler progressHandler = new Handler() 
 {

     public void handleMessage(Message msg1) 
     {

         progDailog.dismiss();
         }
 }
+5
source

All Articles