0
OnClick and onClickListener
what would I lose if I used onClick method instead of onClickListener interface?
4 ответов
+ 3
Hello, Ahmed Mohamed !
I'm not sure that the question is clear.
onClickListener is the interface that defines the onClick() method. If you have a class that intends to listen for clicks, you need to implement the interface (if it does not already extend the class that does), and implement this method too. You must use both; they are not alternatives.
+ 1
Using the event listener is generally better. It is much easier to have multiple onclick events if you use the listener, rather than the HTML attribute. You can add and remove events, without having to edit the onclick attribute (which is saved similarly to a string). However, some old browsers don't fully support the listener.
+ 1
James I don't actually understand the multiple events part, I think I can have multiple events using the onClick method too
+ 1
Alexander Sokolov i mean using the onClick attribute in xml then making a method in Java without writing the onclicklistener line of code