Reputation: 3150
the scenario that I'm trying to accomplish is the following: I have the main layout - that is a framLayout, and inside it I have linearLayouts that contains different view. I want that the global frameLayout will receive a touch event form the child view classes.
In every child view I'm getting the global frameLayout object, and doing setOnTouchListener on it. Then, from the UI, when I'm touching the last view that was inserted to the inner linearLayout, I'm getting the touch event. but for the other views I don't.
FramLayout
LinearLayout
View1 - not getting touch event
View2 - not getting touch event
View3 - not getting touch event
View4 - getting touch event
does anyone encountered in similar behavior?
Upvotes: 1
Views: 1015
Reputation: 23439
hmm... without code, it's a bit tricky to diagnose, but i'm suspecting this scenario ->
you're setting onTouchListener 4 times to the Framelayout, but each time you call it, it is replacing the previous onTouchListener. That's why your last onTouchListener is the only one that seems to work. if such is the case, you can instead take the code you want your FrameLayout's onTouchListener to do... and put it somewhere global, so that each child view's onTouch will trigger that global function. make sense?
also, if my answer is correct (along with everyone else that has answered your questions), will you please mark our answers as correct? you can do so by clicking the empty checkmark to the left of my answer. it's right below the number (rating)
Upvotes: 3
Reputation: 86958
In every child view I'm getting the global frameLayout object, and doing setOnTouchListener on it.
A View can only have one OnTouchListener. You are overwriting the previous listener when you set a new one.
Upvotes: 1