Android中的onPress/onRelease

neb*_*kat 7 android

在flash中有没有任何类型的onPress和onRelease for android按钮?

小智 22

试试这个:

    someView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            if (arg1.getAction()==MotionEvent.ACTION_DOWN)
                runEnemy(); 
            else
                stopEnemy();
            return true;
        }
    });
Run Code Online (Sandbox Code Playgroud)

arg1.getAction()== 0这是指ACTION_DOWN http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN


小智 15

现在为时已晚,但也许有人会发现它很有用:

mButton.setOnTouchListener(new OnTouchListener()
        {

            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                if (event.getAction() == MotionEvent.ACTION_DOWN)
                    Log.d("Pressed", "Button pressed");
                else if (event.getAction() == MotionEvent.ACTION_UP)

                 Log.d("Released", "Button released");
                // TODO Auto-generated method stub
                return false;
            }
        });
Run Code Online (Sandbox Code Playgroud)


Fal*_*rri 8

是.您必须使用OnTouchListener而不是onClickListener.http://developer.android.com/reference/android/view/View.OnTouchListener.html

此外,这与闪存无关,不应标记为闪存.