0

I want to apply some delay in my code. In my code, there are buttons and when I click the buttons, timer will start. After 2 seconds, code again continues.

Enes
  • 89
  • 1
  • 2
  • 8

1 Answers1

0

Firstly, if you are asking some question please provide us with the code that is creating problem. Now, as per your question is suppose you have used onclicklistener, so to make a break of say 5 seconds there is a proper class provided that is called "Handler". Now, i can show you a bit of example,

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new Handler().postDelay(
                new Thread(new Runnable() {
                @Override
                public void run() {
                    //Add your task here
                }
        }
    }, 5000);      //5000 here shows you in milliseconds, so its 5 seconds
Ravi Rathore
  • 101
  • 1
  • 11