MotionEvent.ACTION_UP in text form

My TextView does not support MotionEvent.Action_UP. I get 0 only on event.getAction.

But the same code works perfect for ImageButton.

Does Textview support MotionEvent.Action_UP?

textView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View v, final MotionEvent event) { Log.v("tag","textView"+event.getAction()); if (event.getAction() == MotionEvent.ACTION_DOWN) { Log.v("tag","textViewmousedown"); } else if(event.getAction() == MotionEvent.ACTION_UP) { //This gets never called Log.v("tag","textViewmouseup"); if (standardButtonClickListener != null) { standardButtonClickListener.onStandardButtonClick(v); } } return false; } }); 
+6
source share
2 answers

You should return true instead of false in your onTouch method. In this way, further events will be delivered to your listener.

+13
source

Don't forget MotionEvent.ACTION_CANCEL

  @Override public boolean onTouch(final View view, final MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { setColorFilter(Color.argb(155, 185, 185, 185)); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) { setColorFilter(Color.argb(0, 185, 185, 185)); } return false; } 
-1
source

Source: https://habr.com/ru/post/894176/


All Articles