Hi,
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction == MotionEvent.ACTION_POINTER_DOWN){
for(int ptrIndex = 0; ptrIndex < motionEvent.getPointerCount();
ptrIndex++)
{
int id = motionEvent.getPointerId(ptrIndex);
int x = (int) motionEvent.getX(ptrIndex);
int y = (int) motionEvent.getY(ptrIndex);
if(x < 0){ /* because I was getting negative co-ordinates
when I had more than one pointers */
x=-x
}
if(y < 0){
y=-y
}
View v = checkForMatchViews(x,y);
switch(v.getId()) {
case R.id.touchedView1: // Do the action relative to views;
...
...
...
}
}
}
//Method to check the matching views with co-ordinates..
public View checkViews(int x, int y) {
Log.i("CHECK VIEWS CALLED","CHECK VIEWS CALLED");
int location1[] = new int[2];
...
...
touchedView1.getLocationOnScreen(location1);
...
...
...//for other views in Activity
if(location1[0] <= x && x <= (location1[0] + left.getWidth()) &&
location1[1] <= y && y <= (location1[1] + left.getHeight())) {
return touchedView1;
}
this is the code
On Wed, May 2, 2012 at 3:15 PM, Jason Teagle <[email protected]> wrote:
> I tried to get the x and y coordinates of one view. why..getx and gety
>> co-ordinates
>> are not matching the view which is touched
>>
>
> If you want some help with your problem, try posting some code. Presumably
> you're talking about a listener and the methods it contains - so post the
> code that adds the listener, give us a brief idea of what it is being added
> to, and show us the code for the methods the listener implements. *Then* we
> might be able to answer your question. Without a code sample we have
> nothing to go on. The more information you can give, the better chance we
> have of being able to help.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to
> android-developers@**googlegroups.com<[email protected]>
> To unsubscribe from this group, send email to
> android-developers+**[email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en