-3

I want to avoid null pointer exception for the following.

I want to disable touch listener for a relative layout.

private RelativeLayout    container ;

container.setOnTouchListener(null);

Thank you

Souheib Selmi
  • 329
  • 2
  • 9
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Aaron Nov 22 '18 at 09:47
  • 1
    Nahh duplicate of: https://stackoverflow.com/questions/5418510/disable-the-touch-events-for-all-the-views – Gelldur Nov 22 '18 at 09:51
  • This is *not* a duplicate of the NPE question even though setting the listener to ``null`` causes one to be thrown. This question is about how to strop android from calling the listener for that particular view. – f1sh Nov 22 '18 at 09:53
  • `setOnTouchListener(null)` will not cause an NPE. – Mike M. Nov 22 '18 at 10:05

1 Answers1

0

Disable your RelativeLayout so that touch events never triggered .Use

container.setEnabled(false);
sasikumar
  • 12,540
  • 3
  • 28
  • 48