6

I have created a game where if the user presses a button, it moves the snake in that particular direction.

Rather then when you PRESS a button, I want to make it so when the finger is hovering over the button the snake moves instead.

So I have changed my methods from setOnTouchListener, to setOnHoverListener

here is my code:

Button btnRight = (Button) findViewById(R.id.btnRight);
btnRight.setOnHoverListener(new OnHoverListener(){
    public boolean onHover(View v, MotionEvent event) {
        if(direction!=4)
            direction = 6;
        return false;
    }
});

When the finger is pressed on the screen and gets dragged over the button, nothing happens.

How would I go about having it register when the finger is dragged over the button? Is there an easy method solution or am I gonna have to detect coordinates, etc?

NG_
  • 6,895
  • 7
  • 45
  • 67
Jacob Weber
  • 103
  • 1
  • 7
  • I don't think that commonly used touch displays can tell you that you are just 'hovering' your finger. – nothrow Jan 15 '13 at 20:32
  • Yes, you have to check the coordinates where the finger is pressed, and compare them to the coordinates of the button. – Robert Harvey Jan 15 '13 at 20:33
  • 1
    On re-read I see what you're trying to do. You want to let someone touch the screen anywhere, drag their finger over the button, and then register that their finger is over the button without required a new click (i.e. they don't have to touch the button directly) – Rarw Jan 15 '13 at 21:19
  • 4
    just so don't waste time with it, the onHover method is reserved for pointer capable devices (i.e. mouse, stylus, ...) – ggenglish Jan 15 '13 at 21:53

0 Answers0