In the first method, you entire class Activity implement the OnClickListener interface. You can set the OnClickListener each view to this and receive all click events in one way, where you can then filter them and act on them.
The second method uses an anonymous inner class that implements the interface method. Using this approach, you only receive events for this particular view.
In the first method, your entire class uses one single instance of OnClickListener , which is passed to all the views you want to listen for clicks.
The second method translates as:
Button.OnClickListener anonymous_listener = new Button.OnClickListener() { ... }; button.setOnClickListener(anonymous_listener);
That is, it dynamically creates and saves a new instance of OnClickListener when you use it.
source share