onPress/onRelease in Android
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
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;
}
});
Yes. Instead of an onClickListener, you have to use an OnTouchListener. http://developer.android.com/reference/android/view/View.OnTouchListener.html