-2

In previous projects I have typically created an OnClickListener for any view which needed handle click interaction.

In more recent projects, I have implemented View.OnClickListener, and then overridden the onClick method of the activity to achieve the same result.

Is there an advantage in terms of performance of one implementation over the other, or is there a best practice for deciding which implementation is most appropriate for a particular situation?

Alex
  • 1,643
  • 1
  • 14
  • 32
letsintegreat
  • 3,328
  • 4
  • 18
  • 39

2 Answers2

1

Change version number from26.1.0 to 26.4.0 in your dependencies

NIKHIL NEDIYODATH
  • 2,703
  • 5
  • 24
  • 30
1

There is no best practice defined by Android regarding registering click listeners. It totally depends on your use case.

Implementing the View.OnClickListener interface to Activity is the way to go. As Android strongly recommends interface implementation over and over again whether it is an Activity or Fragment.