Haider Ali
Haider Ali

Reputation: 53

ProgressDialog Box Dummy Timer

Hey guys i wanted to ask if i can add dummy timer to my progress box.

I want my progress box to prompt user to enter his current location then his destination so when the app starts it will prompt him to enter his username, after 2 seconds of msg displaying the msg will dissapear. How can i implement his

code so far:

int timer = 0;
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Enter Current Location");
progressDialog.show();

// do { ++timer; } while ( timer != 500 ); // hiding after 500 iterations
progressDialog.hide();

The do while loop doesn't work for me, so are there other options?

Upvotes: 1

Views: 72

Answers (1)

Martin Gardener
Martin Gardener

Reputation: 1001

Its called delay and not dummy timer.

To add delay, add this code after progressDialog.show() function.

1500 ms delay (1.5 seconds);

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {
        progressDialog.dismiss();
    }   }, 1500); 

or 3000 ms delay (3 seconds);

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {
        progressDialog.dismiss();
    }   }, 3000);  

and remove progressDialog.dismiss() from end of your code after adding any of the above one.

Cheers.

Upvotes: 2

Related Questions