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.
asked Oct 16, 2015 at 19:38
Jeroen
4131 gold badge4 silver badges16 bronze badges
-
See if this helps you: stackoverflow.com/questions/5454448/…Chris Stillwell– Chris Stillwell2015年10月16日 20:03:12 +00:00Commented Oct 16, 2015 at 20:03
-
I tried that too but it did the same.Jeroen– Jeroen2015年10月16日 20:04:59 +00:00Commented Oct 16, 2015 at 20:04
1 Answer 1
The code is correct. I tried it with another mouse and it works.
answered Oct 17, 2015 at 20:45
Jeroen
4131 gold badge4 silver badges16 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-java