0

I'm fairly new to android programming but I have a questions about clicking on buttons

I've tried several tutorials but not sure if I get something

when I need a button to do something for me, I can do it in to ways:

a.add the line - android:onClick="methodName"

b. or just add an onClink listener

what is the difference between these to ways? or maybe they are not doing the same thing at all and I'm just confused? thanks.

TzurEl
  • 792
  • 3
  • 9
  • 15
  • That's just two ways doing the same thing http://stackoverflow.com/questions/4153517/how-exactly-does-the-androidonclick-xml-attribute-differ-from-setonclicklistene – Fidan Hakaj Feb 18 '14 at 22:51

2 Answers2

0

They do the same thing.

In case A you have to just implement onClick method.

In case B you have to first set OnClickListener and then implement onClick method.

Sharjeel
  • 15,588
  • 14
  • 58
  • 89
0

One is set in the xml file, the other is set at runtime. That's the primary difference.

The other difference is setting method name in xml makes it literally look for a method name, so you can plug it into different activities, that implement the method differently, and as long as the method uses that name, it will execute.

NameSpace
  • 10,009
  • 3
  • 39
  • 40