简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM