to show a background process i used ProgressDialogBox.
My code is as
add_button.setOnClickListener(new OnClickListener() {
public void onClick(View viewParam) {
progressDialog = ProgressDialog.show(AddTicketActivity.this, "", "Loading...");
new Thread() {
public void run() {
try{
sleep(10000);
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
progressDialog.dismiss();
}
}.start();
Its working fine. But the problem is progess shows for 10000 ms where as i want it to show untill my data is fetched/added. i mean it should be dependent on fetching/adding time.
i thought to do like it
public void onClick(View viewParam) {
progressDialog = ProgressDialog.show(AddTicketActivity.this, "", "Loading...");
Fetching data code here
progressDialog.dismiss();
}
But it dint work, does not show any progress bar.
How can i use it.
Thanks.
Well your code is fine :
This should work, as long as your are fetching the code in the same thread (although that might lead to an ANR. Consider using
AsyncTask).EDIT : Note that if you are fetching data in a separate thread, according to your logic you will show your progress dialog and then immediately close it.