Reputation: 13477
Just a quick question to confirm the documentation:
The getY(int) function from MotionEvent in the Android confuses me with its documentation:
Returns the Y coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.
With that I thought that the code should be written like this:
for(int i = 0; i < event.getPointerCount(); ++i) {
// Some code...
int currentPointer = event.getPointerId(i);
float currentY = event.getY(currentPointer);
Log.i("test", "Pointer " + currentPointer + " has Y-coord of " + currentY);
// Some more code ...
}
However, in testing on my Samsung Galaxy Tab it appears that I should not pass currentPointer into getY but rather just the 'i' like so:
for(int i = 0; i < event.getPointerCount(); ++i) {
// Some code...
int currentPointer = event.getPointerId(i);
float currentY = event.getY(i);
Log.i("test", "Pointer " + currentPointer + " has Y-coord of " + currentY);
// Some more code ...
}
Is that the correct way of using the getPointerId and getY functions? You give them the both the same 'i' variable and never their actual pointer id's?
I am asking because I want to make sure that this is not different on just my device and this is indeed the way that it is intended to work. Thanks.
Upvotes: 1
Views: 355
Reputation: 3225
Yes, it's correct, you should specify only "i".
All the getPointer*(int) methods take the same index as parameter.
Upvotes: 1