0

I am writing a Quiz. I have four buttons: answer options, and i am using Android multitouch! hack anyone? code snippet to disable multitouch.

But the buttons seem to work only if you tap on them very quickly.

If you slowly press the button and then release it, button only blinks, and nothing happens. Could someone help me figure out how to fix this?

Community
  • 1
  • 1
MrAs
  • 77
  • 8
  • You can try to make a boolean flag that can be set to true if a button is pressed and whenever the button is pressed check if the flag is true and if it is, you can just do nothing.. I think it will simplify your work.. let us know if this is not a good idea for you – Cata Oct 03 '12 at 15:05
  • @Cata i have tried smthing like `public void acceptAnswer(View v) { if (isTriggered){ return; } isTriggered = true; switch (v.getId()) ...` but that does not work (I also can't figure out why). – MrAs Oct 03 '12 at 15:54

2 Answers2

0

Here is a piece of code that might work, please note that I didn't had the time to try it..

private static final String sClickKey = "clickkey";
private boolean mClicked;

@Override
public void onClick(View view) {

    synchronized (sClickKey){

        if (!mClicked){
            mClicked = true;
            /* do the rest here... */
        }

    }

}

Using synchronize will ensure that only the first tapped button will enter in the if(!mClicked), after that the mClicked value is changed to true so the next event will not pass in the if statement..

I hope this helps! ;)

Cata
  • 11,133
  • 11
  • 65
  • 86
0

I have used @JQCorreia hack and overrided his "onTouchEvent" like this:

        @Override
        public boolean onTouchEvent(MotionEvent event){
        int action = event.getAction() & MotionEvent.ACTION_MASK;

        switch (action) {
        case MotionEvent.ACTION_DOWN:
            for(View v: views){
                Rect r = new Rect();
                v.getGlobalVisibleRect(r);
                if (event.getX() > r.left && event.getX() < r.right
                        && event.getY() > r.top
                        && event.getY() < r.bottom) {
                    v.onTouchEvent(event);
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            for(View v: views){
                Rect r = new Rect();
                v.getGlobalVisibleRect(r);
                if (event.getX() > r.left && event.getX() < r.right
                        && event.getY() > r.top
                        && event.getY() < r.bottom) {
                    v.onTouchEvent(event);
                }
            }
            break;
        case MotionEvent.ACTION_MOVE:
            for(View v: views){
                Rect r = new Rect();
                v.getGlobalVisibleRect(r);
                if (event.getX() > r.left && event.getX() < r.right
                        && event.getY() > r.top
                        && event.getY() < r.bottom) {
                }
                else{
                    v.onTouchEvent(event);
                }
            }
            break;
        }
        return true;
    }

That works for me.

Community
  • 1
  • 1
MrAs
  • 77
  • 8