Created
October 20, 2011 08:02
-
-
Save yeradis/1300642 to your computer and use it in GitHub Desktop.
show progress bar for loading data on Button click in android #android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
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
Thanks