i’m new to android (and programming in general), and i was wondering why the OnClickListener interface is under View. For instance, i might set up a button, that when you click on the button, i show a toast message. Why does the onclicklistener need to know anything about a view?
So i understand what a callback is, and why you make the OnClickListener interface something that the developer implement. It’s reusable. But maybe i don’t really understand encapsulation? or maybe i’m totally missing the point of interfaces and callback?
This is more of a conceptual questions, and i would highly appreciate any answers with explanation of the concept as well as maybe simple/short example code to explain.
Thanks!
The major views we are using are sub classes of View class. See this
Android defined many Interfaces in View class to handle some events, which are all common to any view type(Button, TextView, etc.). To make the API simple and providing easier way to programmers. This is actually the concept of inheritance in OOPS.
If you have any doubts refer Android Developers website, you will get complete details there.