Skip to content

Instantly share code, notes, and snippets.

@yeradis
Created October 20, 2011 08:02
Show Gist options
  • Save yeradis/1300642 to your computer and use it in GitHub Desktop.
Save yeradis/1300642 to your computer and use it in GitHub Desktop.
show progress bar for loading data on Button click in android #android
#android
This is what you need:
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final ProgressDialog progress = ProgressDialog.show(THENAMEOFYOURACTIVITYCLASS.this,
ProgressTitle, ProgressMessage, true, false);
new Thread(new Runnable() {
public void run() {
loadFeed();
progress.cancel();
}
}).start();
}
});
Be careful about what loadFeed(statutory); do. Because now is working inside a THREAD and Threads con not modify UI, If this is the case then you should do something like this:
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final ProgressDialog progress = ProgressDialog.show(THENAMEOFYOURACTIVITYCLASS.this,
ProgressTitle, ProgressMessage, true, false);
new Thread(new Runnable() {
public void run() {
loadFeed(); //just load data and prepare the model
runOnUiThread(new Runnable() {
@Override public void run() {
//here you can modify UI here
//modifiying UI element happen here and at the end you cancel the progress dialog
progress.cancel();
}
}); // runOnUIthread
}
}).start();
}
});
Pd: this is a memory stuff, can break your build so sorry if there is a missing param or something like that
@kriishna
Copy link

thanks a lot for you helping code............

@gulzaar
Copy link

gulzaar commented Sep 26, 2015

thanks

@iamAbayomi
Copy link

Thanks

@charity1475
Copy link

And how about in JavaFX , onAction event?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment