Doubt on how to handle the Button event

Asked

Viewed 13 times

0

Hello! I am new in programming and Android and I came across a question.

What I see in most tutorials is like this.

  1. A button is created.
  2. Declares this button as class attribute.
  3. Retrieves his reference via id inside onCreate.
  4. Apply a Listener to this button and make the implementation.

Only the other day I saw something different.

  1. A button is created.
  2. A public method is created by receiving a View object as a parameter.
  3. In the onClick attribute of xml this button points to this method and implements it.

The fact that I neither declare nor recover the reference can generate me some problem?

thank you

  • the only problem you could have would be the fact that you need the same button at another point on the screen, but triggering another event.

  • Related: https://stackoverflow.com/questions/21319996/android-onclick-in-xml-vs-onclicklistener

  • thank you all, I will read the link

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.