0

Ok... in my app i update the layout on MotionEvent.ACTION_DOWN and then i check the motion event coordinates to locate my buttons. I can show a toast when finger is released on different buttons. The problem is i need a long touch on my buttons to call another action without conflicting with the MotionEvent.ACTION_UP. Implemented a long click handler but since i don't 'click' its not working. Hope you guys understand my problem.

Whats the best way to get my app working as intended?

My class implements OnTouchListener, OnGestureListener

    @Override
public boolean onTouch(View v, MotionEvent event) {

    switch(event.getAction()){

    case MotionEvent.ACTION_DOWN:

        // UPDATE LAYOUT
            break;

        case MotionEvent.ACTION_UP:

        // GET BUTTON X Y           
            if (x and y match the button location){

                // DO ACTION

            }else{   

                // DO NOTHING

            }           
            // CHANGE LAYOUT TO INITIAL STATE   
            break;

        case MotionEvent.ACTION_MOVE:
            break;

    }

        return false;


     mybutton.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
                // DO STUFF
            return true;
        }
    });

}

1 Answers1

0

just try to return false in your onTouch(...) method and use onLongClickListener(...) as usual

user1049280
  • 5,176
  • 8
  • 35
  • 52
  • Think thats what i tried... updated the code. I need the long touch straight out of the move event without lifting the finger and touching again since my layout will switch back to normal state after motionEvent_UP. – user1915113 Jan 21 '13 at 15:07
  • well, then you need to add some timer to your onTouchEvent() and start in on ACTION_DOWN - this way you could implement your own onLongClickListener(...) but don't forget to check finger position periodically – user1049280 Jan 21 '13 at 15:14
  • yeah like i do with my button position i guess... is there a way to get rid of the constant x y update when reaching the button area. it will fire the event more than once since it's so sensitive. And how would i avoid that the up event is fired when i detect my long touch timer... guess both fire on motionEvent_UP. – user1915113 Jan 22 '13 at 07:38
  • You implement your timer on ACTION_DOWN so it fires only once when you touch button, it doesn't matter what you are doing after that. – user1049280 Jan 22 '13 at 08:04