-4

I have a custom view that I created by extending the View class. My custom view overrides the onTouchEvent. I want to be able to turn the view's ability to listen on and off. I need to do that from within the view. Does anyone know how I can accomplish this? Simply calling

  setEnabled(false);

does not work.

cafebabe1991
  • 4,928
  • 2
  • 34
  • 42
learner
  • 11,490
  • 26
  • 97
  • 169
  • go through this link..may be it will help u. http://stackoverflow.com/questions/5418510/disable-the-touch-events-for-all-the-views – Anjali Tripathi Jan 22 '14 at 06:44

2 Answers2

1

Try by setting the following

setOnTouchListener(null)

cafebabe1991
  • 4,928
  • 2
  • 34
  • 42
1

I'm not sure if this is the right solution but it works:

        this.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return true;
            }
        });

This blocks other touch related Listeners from receiving the Event, so onTouchEvent won't be invoked.

you can use setOnTouchListener(null) to go back to your normal state so that your onTouchEvent works again.

if you had figured out a better solution i hope that you post it.

habibhassani
  • 486
  • 1
  • 6
  • 15