No you cant just add onTouch to each button. The way multitouch is
designed it will only work inside one view. You will need to draw
everything yourself  - you cant use multitouch over multiple view
objects. It only works inside one View. Create a big view covering the
screen, draw the contents yourself, and you can then get multitouch
positions accurately.

I know it sucks, right? I complained about it originally too but they
didnt agree with me...


-niko

On May 11, 6:31 am, momojo <jason.kah...@gmail.com> wrote:
> Ok So I've gone through several tutorials on the web. I understand how
> the pointerCount works , I can get two points, etc, etc. My problem is
> I am trying to implement a game control, i.e. dpad and some buttons.
> The "buttons" are actually TextView objects with images. I Implement
> OnTouchListener Interface. my onTouch Method gets called when it
> should. The problem is if I have finger #1 on button a then press
> finger #2 on button b my OnTouch() method is called with the view of
> button a, not button b. Fine then I will just get the bounds of the
> buttons and see if they intersect with the points clicked. No luck, It
> seems as though the points that come in the MotionEvent are not
> relative to 0,0 , but to some other coordinate system. I would have
> thought all points were relative to upper left of screen. Here is my
> code.
>
> protected void onFinishInflate()
> {
>     dpadView = findViewById(R.id.dpad);
>     dpadView.setOnTouchListener(this);
>     aButton = (TextView)findViewById(R.id.a_button);
>     aButton.setOnTouchListener(this);
>     bButton = (TextView)findViewById(R.id.b_button);
>     bButton.setOnTouchListener(this);
>
> }
>
> public boolean onTouch(View v, MotionEvent event)
> {
>             // Dump touch event to log
>             // V.getId() is always equal to what the 1st finger is
> pressed on!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>             Log.d("Controller","id:" +v.getId());
>
>             dumpEvent(event);
>             if(buttonHit(event,v))
>             {
>
>             }
>             return true; // indicate event was handled
>          }
>
> private boolean buttonHit(MotionEvent event, View view)
>     {
>         for(int i=0;i<event.getPointerCount();i++)
>         {
>             int pointerId = event.getPointerId(i);
>             int pointerX = (int)event.getX(pointerId);
>             int pointerY = (int)event.getY(pointerId);
>
>             Rect rect = new Rect();
>
>             view.getGlobalVisibleRect(rect);
>             //view.getGlobalVisibleRect(rect);
>             view.setBackgroundColor(Color.BLACK);
>
>             Log.d("Controller", "pointer (" + pointerX + "," +
> pointerY + ")" );
>             Log.d("Controller", "bounds [(" + rect.left + "," +
> rect.top + ")-(" +  rect.right + "," +
>                     rect.bottom + ")]");
>             if( rect.contains(pointerX, pointerY))
>             {
>                 view.setBackgroundColor(Color.CYAN);
>
>                 Log.d("Controller","Hit button");
>
> view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
>                 return true;
>             }
>         }
>         return false;
>
>     }
>
> I saw some posts from Romain Guy on Stack Overflow that said you can
> just add on OnTouchListener to each "Button" but when I do so I do not
> get a second event. Has anyone done this? Is there an example
> somewhere?
>
> --
> 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
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to