-
-
Save SOF3/07c3c110aa214fcdd752e95573b7076f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class handle{ | |
private boolean done = false; | |
public void onClick(View v){ | |
final Handler handler = new Handler(); | |
final Random random = new Random(); | |
Runnable toast = new Runnable(){ | |
@Override | |
public void run(){ | |
if(done){ | |
Toast.makeText(getBaseContext(), "Done", LENGTH_SHORT).show(); | |
}else{ | |
Toast.makeText(getBaseContext(), "Please wait", LENGTH_SHORT).show(); | |
handler.postDelayed(this, 1000); | |
} | |
} | |
}; | |
Runnable yourFunc = new Runnable(){ | |
private int count = 0; | |
@Override | |
public void run(){ | |
count++; | |
runYourFunc(); | |
if(count >= 20){ | |
done = true; | |
}else{ | |
handler.postDelayed(this, random.nextInt(5000)); | |
} | |
} | |
} | |
runnable.run(); | |
handler.postDelayed(yourFunc, random.nextInt(5000)); | |
} | |
private void runYourFunc(){ | |
// your function here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment