HydroHeiperGen
HydroHeiperGen

Reputation: 121

How to detect Button pressed state?

I need a constant trigger, while a button is pressed, therefore I look for an ACTION_BUTTON_PRESS event, but it doesn't work.

private View.OnGenericMotionListener onWidthClickListener = new OnGenericMotionListener() {
    @Override
    public boolean onGenericMotion(View v, MotionEvent event) {
      switch (event.getActionMasked()) {
        case MotionEvent.ACTION_BUTTON_PRESS:
          Log.d(TAG, "ACTION_BUTTON_PRESS");
          break;
        case MotionEvent.ACTION_BUTTON_RELEASE:
          Log.d(TAG, "ACTION_BUTTON_RELEASE");
          break;
        case MotionEvent.ACTION_CANCEL:
          Log.d(TAG, "ACTION_CANCEL");
          break;
        case MotionEvent.ACTION_DOWN:
          Log.d(TAG, "ACTION_DOWN");
          break;
        case MotionEvent.ACTION_UP:
          Log.d(TAG, "ACTION_UP");
          break;
      }
      return false;
    }
  };

Using an OnTouchListener and ACTION_MOVE just gives me Information, when I move inside the button panel, but I want to move the button around and while doing this, I want the event MOVE triggered.

Upvotes: 0

Views: 338

Answers (1)

user2836202
user2836202

Reputation: 639

View has View#isPressed(). Therefore you could always check #isPressed() while you're doing whatever it is you're trying to do.

Upvotes: 1

Related Questions