2

I am adding a Fragment fragment with clickable views to my Activity.

I have noticed that if I click on a point inside that Fragment which does not have any OnClickListener, the click event leaks to the layout below, in this case, the Activity layout. If there is a view with its own OnClickListener in that point, its code is executed. I can prevent this click by adding a dummy OnClickListener to the Fragment background but I want to know if there is a better option.

Thanks

kenny_k
  • 3,831
  • 5
  • 30
  • 41
Juanje
  • 1,235
  • 2
  • 11
  • 28

2 Answers2

2

You can simply add

android:clickable="true"

property to the parent view of your layout as described here or here.

AloDev
  • 410
  • 3
  • 13
  • @Juanje welcome to Stack Overflow. Please note that the preferred way of saying 'thanks' around here is by up-voting good questions and helpful answers (once you have enough reputation to do so), and by accepting the most helpful answer to any question you ask (which also gives you a small boost to your reputation). Please see the [About] page and also [How do I ask questions here?](https://stackoverflow.com/help/how-to-ask) – kenny_k Dec 26 '17 at 15:39
0

set background color to your fragment layout and set layout width and height to match parent. May be it will solve your problem