通过按钮进行动作

时间:2018-07-28 10:24:09

标签: android motionevent

我正在构建一个计算器应用程序,并且尝试使用“滑动”动作来切换我的活动,问题是在通过按钮执行动作事件时未记录该动作事件。空白空间,我可以毫无问题地切换活动...

这是我用来实现“滑动”的代码:

public boolean onTouchEvent(MotionEvent swipe)
{
    switch ( swipe.getAction() ) {

        case MotionEvent.ACTION_DOWN: // records the coords for the start of the motion
             x1 = swipe.getX();
             y1 = swipe.getY();
            break;
        case MotionEvent.ACTION_UP: // records the coords for the end of the motion
            x2 = swipe.getX();
            y2 = swipe.getY();
            if( x1 < x2)
            {
                Intent i = new Intent(BasicCalculator.this , AdvancedFunctions.class);
                startActivity(i);
            }
            break;
    }

        return false;
}

0 个答案:

没有答案
相关问题