1.Left or touchedView1 is the Button..on which the setOnTouchListener is
called in main Activity.
OK, why have two variables referring to the same object? That can only lead
to confusion.
So you're trying to identify the button being touched? Can I ask why you use
an OnTouch listener rather than an OnClick listener?
Also, I'm a little confused - the prototype for the onTouch() method
includes a View object - the view that received the event. Why do you need
to find the view that was touched when it is being *given* to you in the
handler?
As far as I know (my Android experience is very limited, so someone may be
able to correct me here), events are only dispatched to the widget / view
that they occur on, so if onTouch is called, the View object supplied *is*
the one that was touched - it cannot receive an onTouch event for any other
view. You can easily check this by adding the OnTouchListener to only one
button and nothing else, and then see if the handler gets called when you
touch something *other* than the button. I do not expect that to happen, but
best to check.
However, let us put that issue aside for a moment and deal with one of your
other problems:
2.Even after using Rect it doesn't give the desired result.
(No, I didn't expect it to fix anything - it just made things a little
easier to understand when you come back and read your code in a year or so's
time! Been there, done that... )
4.Yes,I do get the finger count and pointer count balanced i.e restricted
to 2...but the
rest is not working.
OK, good - no phantom information being supplied. One less problem to worry
about.
3.Single pointer (i.e just ACTION_DOWN)also doesn't identify the view.
OK, that is what we should concentrate on. For testing purposes, do the
following:
1. Create just one button and one TextView in your app (we'll use the
TextView to display information).
2. Add the OnTouchListener to *only* that button, no other view.
3. Touch the button with one finger only, to trigger the handler.
4. In that handler, gather information about the button's location on
screen, its dimensions, and the values coming from the MotionEvent. Set this
information into the TextView so that you can see it easily, something like
this:
int[] location1 = new int[2];
touchedView1.getLocationOnScreen(location1);
myTextView.setText(""
+ location1[0] + ", " // Left
+ location1[1] + ", " // Top
+ (location1[0] + touchedView.getWidth() ) + ", " // Right
+ (location1[1] + touchedView.getHeight() ) + " & " // Bottom
+ event.getX() + ", " // Event x position
+ event.getY() + ", "); // Event y position
5. Examine the results - do they make sense (write them here, to satisfy my
curiosity!)?
--
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