Question

My Android Activity contains multiple buttons that all need an OnClickListener. I've seen lots of different ways of doing this such as::

  • Implementing the interface in activity class
  • Creating a separate class that implements the interface
  • Defining an anonymous inner class for each button.

I've seen many examples of each approach. However, its not clear to me why one approach would be used instead of another. Are the differences between these approaches stylistic or are there reasons that make one approach better?

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top