3

So I have an EditText view, what I want to do is execute some code if the user touches the EditText view but execute another code if the user does a long touch/click, the problem I'm facing is that onTouch is always executed first before onLongClick, is there anyway to detect that if the user long presses to only execute that code and not the code in onTouch ?

Eric Bergman
  • 1,453
  • 11
  • 46
  • 84
  • 1
    The answer is here: http://stackoverflow.com/questions/5471959/android-how-to-call-ontouch-only-after-an-onlongclick#answer-5471979 – Yehor Nemov Mar 28 '14 at 14:29
  • @ghoshak that solution didn't work for me. In that solution the onTouch event is not executed the first time and when I long click both functions are executed. – Eric Bergman Mar 28 '14 at 14:40
  • what you want to do when a user long click? you can click *double click* instead of *longclick*? – CompEng Mar 28 '14 at 14:52
  • @Ersin Gülbahar When I do a normal/single touch or click I want to display a dialog but when I do a long touch/click I want to display a Different dialog. The problem is since onTouch is executed first no matter what both dialogs appear. – Eric Bergman Mar 28 '14 at 14:55
  • You could achieve `onLongClick()` to be called by simply return `false` by `onTouch()`: http://stackoverflow.com/questions/10946751/ontouch-onlongclick-together-in-android#answer-10946881 – Yehor Nemov Mar 28 '14 at 14:55
  • @ghoshak OK I want to do something like this if (longTouch) {Show Dialog 1} else if (normalTouch) {Show Dialog 2} – Eric Bergman Mar 28 '14 at 14:58
  • The problem is that since onTouch is executed before onLongClick I cannot simply create a Boolean variable to indicate whether onLongClick has been pressed. – Eric Bergman Mar 28 '14 at 15:01
  • 1
    For getting things done you have to use `onClickListener` intead of `onTouchListener`. This time different dialogs will be opened. Inspect [UI. Event Listeners](http://developer.android.com/guide/topics/ui/ui-events.html#EventListeners) for information in advance. – Yehor Nemov Mar 28 '14 at 15:12
  • @ghoshak That's exactly what I was looking for, post that as an answer so I can mark it such. – Eric Bergman Mar 28 '14 at 15:17
  • @EricBergman The answer is posted. – Yehor Nemov Mar 28 '14 at 15:26

1 Answers1

1

For getting things done you have to use onClickListener instead of onTouchListener. This time different dialogs will be opened. It works because long click and click are the same level (defined) actions while touch could be any action user performs (click, long click, focus changing, etc).

Inspect UI. Event Listeners for information in advance.

Yehor Nemov
  • 907
  • 2
  • 16
  • 31