2

Is it a bad programming practice to set onClick() method in the layout XML file instead of setting OnClickListener() in the java code in an android activity?

Pk boss
  • 274
  • 1
  • 13
Adarshlal
  • 77
  • 1
  • 9
  • There are some considerations to take into account, check this link: http://stackoverflow.com/questions/4153517/how-exactly-does-the-androidonclick-xml-attribute-differ-from-setonclicklistene – zozelfelfo Oct 09 '14 at 05:38

1 Answers1

1

No,not at all,

  • Whenever you set some listener by setOnClickListener() in java class,then you are doing it yourself

  • but when you specify onClick in xml file,you are commanding to android to implement the setOnClickListener for you

.However in both cases the setOnClickListener is getting implemented. You may decide according to your requirements which approach you want to follow.

nobalG
  • 4,544
  • 3
  • 34
  • 72