Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i pass the on click event through a view?

Tags:

android

So I have 3 views, one big one on top of the other two. The one on top is transparent. I want to be able to register an onTouch event on the views behind the big one on top, while the big one does nothing.

How can one do this?

like image 639
Taranasus Avatar asked Oct 16 '11 18:10

Taranasus


People also ask

How do you pass Click event?

you can you use addEventListener("click", function(){blah blah blah}, true) which would pass the event to its children. in the child element, you can handle the event as you wish.

How Pass Click event from parent to child in Android?

Declare your TextView not clickable / focusable by using android:clickable="false" and android:focusable="false" or v. setClickable(false) and v. setFocusable(false) . The click events should be dispatched to the TextView 's parent now.

How listener works in Android?

An event listener is an interface in the View class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI.


1 Answers

Take a look at using onInterceptTouchEvent(TouchEvent) from ViewGroup. The documentation there is pretty clear on how you can achieve what you are after here. You will likely want to extend your transparent parent (unless it is already an extension that you wrote) and override this method to do your bidding.

like image 142
nicholas.hauschild Avatar answered Oct 12 '22 23:10

nicholas.hauschild