Jeroen
Jeroen

Reputation: 413

Tracking mouse cursor android

I have a bluetooth mouse connected to my phone (galaxy s2, Android 4.1). I'm trying to get the cursor position and display it in a TextView using the OnHoverListener:

private class MouseListener implements View.OnHoverListener {
    @Override
    public boolean onHover(View view, MotionEvent motionEvent) {
        String position = motionEvent.getX() + "  " + motionEvent.getY();
        mousePosition.setText(position);

        return false;
    }
}

This is set on a RelativeLayout:

layout.setOnHoverListener(new MouseListener());

The problem is that it only updates when I click and not when I move the mouse.

Upvotes: 0

Views: 1561

Answers (1)

Jeroen
Jeroen

Reputation: 413

The code is correct. I tried it with another mouse and it works.

Upvotes: 1

Related Questions