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
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();
}
}
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);
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With