Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Stop OnTouchListener while user is touching the screen ? < android>

Hey I am looking for a way to force the user on-touch to be cancel and force him to raise his finger again to re-choice.

This is basically my question:

enter image description here

like image 218
Guy Avatar asked Jul 27 '14 00:07

Guy


1 Answers

Option 1:

set OnClickListener instead of OnTouchListener.

Option 2:

catch the ACTION_UP and apply your action only after it.

boolean pressFlag= false; 

public boolean onTouch(View v, MotionEvent event) {
    
    int action = event.getAction();

    switch (action) {

    case MotionEvent.ACTION_DOWN:
      if(pressFlag==false){
         // applay your action
         pressFlag==true;           
      }else{
         //do nothing
      }
      break;
    
    case MotionEvent.ACTION_UP:
      pressFlag==false;
      break;
   
    default:
    break;

    }
  return true;

}

like image 145
wiz Avatar answered Oct 21 '22 00:10

wiz