A
A
Al2017-04-26 19:22:29
Android
Al, 2017-04-26 19:22:29

Is there an equivalent of $(document).on('click') for android?

Is it possible in android to set an event handler before the elements appear? For example, put an OnClickListener on the wrapper container and listen to all clicks there, i.e. it will always check the id of the clicked element.
For example, in javascript you can do this: Here the handler is hung on the body node of the web page, it will be triggered by clicking on an element with an id equal to myElem, it does not matter when such an element was created, before the handler was installed or after. Can this be done in android?
$(document.body).on('click','#myElem',handler)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2017-04-26
@zagayevskiy

In general, no, you can't really do that. If you do not want to write handlers for each element, you can go at least two ways
1) describe the onClick method in xml - I think it is ugly and leads to errors.
2) use ButterKnife and its @OnClick annotation - then it will turn out quite similar to what you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question