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.
Asked
Active
Viewed 562 times
0
-
Welcome to Stack Overflow! Stack Overflow is not a free code writing service, please show your code/effort and what the actual problem is. – Blue Aug 04 '16 at 20:17
-
Ok. Here is my problem. This is my code – Enes Aug 04 '16 at 20:31
-
sorry I am newbie for stackoverflow. I couldnt find how to post code here – Enes Aug 04 '16 at 20:35
1 Answers
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
-
So the task will execute after 5 seconds that you will define within run() method. is this what you are looking for? – Ravi Rathore Aug 04 '16 at 21:03
-