Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onPress/onRelease in Android

Tags:

android

Is there any kind of onPress and onRelease for android buttons like in flash?

like image 830
nebkat Avatar asked Jan 04 '11 19:01

nebkat


3 Answers

try this:

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

arg1.getAction()==0 it's mean ACTION_DOWN http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN

like image 116
ihitang Avatar answered Nov 14 '22 00:11

ihitang


It is too late, but maybe someone will find it useful:

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;
            }
        });
like image 26
Bobans Avatar answered Nov 13 '22 23:11

Bobans


Yes. Instead of an onClickListener, you have to use an OnTouchListener. http://developer.android.com/reference/android/view/View.OnTouchListener.html

like image 8
Falmarri Avatar answered Nov 13 '22 22:11

Falmarri