1

I have a LinearLayout that acts like a container for views.

I'm inflating a different layout programatically and adding an OnClickListener and adding it in my LinearLayout.

What I want to achieve is to have the option to disable those OnClickListener on those views that I've inflated and added to my LinearLayout.

Can I just disable the OnClickListener on the parent LinearLayout to disable as well all the other child's OnClickListener?

Setting the parent LinearLayout click listener to null doesn't work though, any ideas? THanks.

lorraine batol
  • 6,001
  • 16
  • 55
  • 114
  • You could potentially have your `Fragment`/`Activity` implement `View.OnClickListener` and set that as (shared) OnClickListener to both the `LinearLayout` container and it childs. Then it's simply a matter of e.g. toggling a boolean to disable presses on either the whole container or a certain number of child views. In the single listener you can determine the origin by using a swich/case statement on the id of the passed in `View` parameter; e.g. as [demonstrated here](http://stackoverflow.com/a/9196403/1029225). – MH. Nov 28 '12 at 07:01

1 Answers1

0

You can put the onClickListener as null to the views for which you don't want to add the listener instead of setting the listener as null to the parent layout.

Kameswari
  • 738
  • 7
  • 27
  • 1
    the thing is i'm inflating and adding those onclick listener programatically and then just adding them to the parent linear layout, accessing those views now is returning null. – lorraine batol Nov 28 '12 at 07:02