Remove an onclick listener
Solution 1:
mTitleView.setOnClickListener(null)
should do the trick.
A better design might be to do a check of the status in the OnClickListener and then determine whether or not the click should do something vs adding and clearing click listeners.
Solution 2:
Note that if a view is non-clickable (a TextView for example), setting setOnClickListener(null)
will mean the view is clickable. Use mMyView.setClickable(false)
if you don't want your view to be clickable. For example, if you use a xml drawable for the background, which shows different colours for different states, if your view is still clickable, users can click on it and the different background colour will show, which may look weird.
Solution 3:
Perhaps setOnClickListener(null)
?