0

I have made a simple phone pad, numbers 0-9, dial, etc. I have used imagebuttons. I then tried onclick.

The problem with onclick is it activates when you stop pressing the button, not when you actually press the button. I know it's a small thing but it seems odd from a users perspective.

So I tried ontouch with actiondown and imagebuttons, but then multiple ontouch doesn't work so I added multitouch. Now the second or third button makes the first button re-activate instead of the one pressed activate. How can I get a standard phone pad working with with imagebuttons plus multi-touch or something similar?

    ImageButton ibone = (ImageButton) findViewById(R.id.imageButton1);
    ibone.setSoundEffectsEnabled(false);
    ibone.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            int tempy = event.getActionMasked();
            if (tempy == 0 || tempy == 5) { // if an action down primary or secondary touch has occurred then...
                // DO STUFF
            }
            return false;
        }

PS I tried

return true;

to same effect

I am sorry, I really don't understand multi-touch implementation at all.

John Ashmore
  • 1,015
  • 1
  • 10
  • 25
  • possible duplicate of [Triggering event when Button is pressed down in Android](http://stackoverflow.com/questions/2615616/triggering-event-when-button-is-pressed-down-in-android) – Brian Roach Jun 06 '13 at 15:07
  • This is not a duplicate! That link given by Brian tells you to use the code I have already used to initiate ondown/ontouch rather than onup/onclick. If you read the entire introduction I am looking to get multi-touch working correctly, instead of just re-firing the first button pressed only. – John Ashmore Jun 07 '13 at 03:28

2 Answers2

0

Why do you need multi-touch? The setOnTouchListener should trigger every time a view is clicked, regardless of whether or not you use multi-touch...

Try this:

ImageButton ibone = (ImageButton) findViewById(R.id.imageButton1);
ibone.setSoundEffectsEnabled(false);
ibone.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) 
    {
        switch ( event.getAction() ) {
            case MotionEvent.ACTION_DOWN: 
                ---DO STUFF---
                break;
            case MotionEvent.ACTION_UP: break;
        }
        return false; //<--Should be false for your case (I think)
    }
}
dberm22
  • 3,187
  • 1
  • 31
  • 46
  • This is the same as my implementation. The shortcoming being if I hold down one button, then I can't touch another button and have it respond. I kind of need to release the first action down, even if I haven't lifted my finger. I hope I have explained it adequately – John Ashmore Jun 07 '13 at 01:33
  • Please note that there are multiple imagebuttons – John Ashmore Jun 07 '13 at 02:08
0

An answer/tutorial is found at: http://www.passsy.de/multitouch-for-all-views/#comment-47486

This includes most of what you may require.

John Ashmore
  • 1,015
  • 1
  • 10
  • 25