Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android asyncTask dialog Circle

Tags:

android

I been searching all day today trying for find some example code or tutorials how to create a progress circling while the task is being done. The time for this task to complete is vary accordingly and there are lots of samples out there that are using the Thread.sleep(xxxx) make it circling but this is not efficient. Here is what I want to do, I want to load a ListView that populated from a web service using JSON after a button is clicked. The listview is loading up perfectly fine, but it take about 5-10 seconds to load up depending on the size, so I want to show the spinning circling while the user is waiting. Can someone please share some sample code on how to achieve that?

Thank you

like image 739
james winters Avatar asked Feb 07 '12 02:02

james winters


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();
        }
    }
like image 114
brian Avatar answered Nov 13 '22 01:11

brian


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);
like image 31
Jackson Chengalai Avatar answered Nov 12 '22 23:11

Jackson Chengalai


You can try 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();
         }
 }
like image 22
Lucifer Avatar answered Nov 12 '22 23:11

Lucifer