0

I am trying to detect when the user releases an ImageButton long click using this answer, however, I noticed the OnLongClickListener runs twice, I fixed it by returning true instead of false inside the onTouchListener like this:

 private View.OnLongClickListener longClickListener = new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View pView) {
            Log.d("Record", "Start");

            isSpeakButtonLongPressed = true;
            return true;
        }
    };

    private View.OnTouchListener touchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View pView, MotionEvent pEvent) {
            pView.onTouchEvent(pEvent);
            if (pEvent.getAction() == MotionEvent.ACTION_UP) {
                if (isSpeakButtonLongPressed) {
                    Log.d("Record", "stop");

                    isSpeakButtonLongPressed = false;
                }
            }
            return true;
        }
    };

I don't know why this fixed the issue and if it is correct doing this. glad for some explanation.

Community
  • 1
  • 1
DAVIDBALAS1
  • 484
  • 10
  • 31
  • check this, might help you out: http://stackoverflow.com/questions/14877009/events-for-long-click-down-and-long-click-up-in-android – Kushan Jul 23 '16 at 13:54
  • RTFM: https://developer.android.com/reference/android/view/View.OnLongClickListener.html – Chisko Sep 08 '16 at 01:34

0 Answers0