help please !!!!!!!!!

  • Replies:1
Brahim Cedrati
  • Forum posts: 1

Mar 15, 2016, 11:28:09 AM via Website

hi
i have a problem with detecting a swipe
i'm working on a calculator using visual studio and i want to give the user the ability to change
between activity using a swipe
here is the code

    public override bool OnTouchEvent(MotionEvent e)
    {
        int action = (int)e.Action;

        switch (action)
        {
            case (int)MotionEventActions.Down:

                x1 = e.GetX();
                y1 = e.GetY();
                break;

            case (int)MotionEventActions.Up:

                x2 = e.GetX();
                y2 = e.GetY();
                break;
        }
        if (x1 < x2)
        {

            StartActivity(typeof(MainActivity));


        }

        return true;
    }

it works fine on the text view but when i swipe over the buttons
it doesn't work

hope someone could help me out and thanks in advance

Reply
Chris Wu
  • Forum posts: 13

Mar 15, 2016, 2:42:22 PM via Website

Probably button handle onTouch. In my opinion, you should use:

YourButton.requestDisallowInterceptTouchEvent(true);

in MotionEvent.ACTION_DOWN,

and calls performClick() in MotionEvent.ACTION_UP

performClick should be override similar as below:

@Override
public boolean performClick() {
    super.performClick();
    // Handle the action for the custom click here
    return true;
}

Reply