1

Hi i want to show a loading or progress dialog first for 1 second before button do anything else.... please help

    button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

       <!-- want to a Show a Loading or Progress Dailog for 1 Second  -->

            if (isInternetPresent) {
                // Internet Connection is Present
            } else {
                // Internet connection is not present
                InternetNotContectedAlert();
            }
2

1 Answer 1

3

You can just do it like the following:

ProgressDialog csProgress = new ProgressDialog(NextActivity.this);
Button csButton = (Button) findViewById(R.id.buttonCs);
csButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        csProgress.setMessage("Loading...");
        csProgress.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                csProgress.dismiss();
                // whatever you want just you have to launch overhere.
            }
        }, 1000); // just specify the time when you want to launch your action 
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.