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?
Asked
Active
Viewed 107 times
2
-
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 Answers
1
No,not at all,
Whenever you set some listener by
setOnClickListener()
in java class,then you are doing it yourselfbut when you specify
onClick
inxml
file,you are commanding toandroid
to implement thesetOnClickListener
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