Reputation: 1
I'm creating a tapping game, in which the player will tap in the buttons and will earn points. I used random fucntion inside the button onclick to move the button randomly.
I want the button to be triggered again, only if the player is not clicking on it (after some elapsed time), so that it will appear randomly once again.
Upvotes: 0
Views: 58
Reputation: 123
try this, it start after user click at least once time the button
final Handler h = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
//function moveButton
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//....
final long timeToMoveButton = 30000; //milliseconds
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
h.removeCallbacks(runnable);
h.postDelayed(runnable, timeToMoveButton);
}
});
}
if you want move button when app start add in onCreate()
h.postDelayed(runnable, timeToMoveButton);
Upvotes: 0