J'ai une minuterie que je veux démarrer en maintenant enfoncé un bouton, et réinitialiser le minuteur quand je lâche. C'était possible avec onClick mais je n'arrive pas vraiment à comprendre comment utiliser l'événement onTouch dans ce projet. Le premier extrait de code a fonctionné, mais comment implémenter le toucher au lieu du clic d'une manière asy?implémenter l'événement onTouch dans mon timerminject
@Override
public void onClick(View v)
{
if (!timerHasStarted)
{
countDownTimer.start();
timerHasStarted = true;
startB.setText("Start");
}
else
{
countDownTimer.cancel();
timerHasStarted = false;
startB.setText("RESET");
}
}
public boolean onTouch(View v, MotionEvent event) {
final float mouseSensitivity = 0.5f;
if(event.getAction()==MotionEvent.ACTION_DOWN){
countDownTimer.start();
timerHasStarted = true;
} else if(event.getAction()==MotionEvent.ACTION_UP){
countDownTimer.cancel();
timerHasStarted = false;
}
return timerHasStarted; } }
public void onTouch(View v, MotionEvent event) {
// final float mouseSensitivity = 0.5f;
if(event.getAction()==MotionEvent.ACTION_DOWN){
countDownTimer.start();
timerHasStarted = true;
} else if(event.getAction()==MotionEvent.ACTION_UP){
countDownTimer.cancel();
timerHasStarted = false;
}
}