I am trying to show a progressbar when a button is clicked. When i test the app it force closes / stops. My app works fine before the progressbar code is added in.
also
try this way, i am not sure it will help you or not
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();
}
});