Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any disadvantage of android:onClick attribute usage?

Tags:

android

What is of these ways is better for onClick's methods implementation: - Using android:onClick attribute in xml - Implementing and defining onClickListener?

like image 774
Eugene Avatar asked Dec 08 '25 20:12

Eugene


1 Answers

In my personal opinion, defining implementing and defining the OnClickListener is much better. The main reason is that it's easier for others to understand how the code works.

When you are reading the code of an Android app you will be reading the .java files (90% of the time) to understand how it works; you will ignore most of the XML layouts which does not tell you how the app actually works or what is its purpose.

Thus, if you use the android:onClick attribute, you will force others (and yourself) to look at both sides: XML layouts and Java source to understand the flow and intention of your app, which is not nice.

Notice that it's a matter of readability; technically speaking there should not be any difference of performance.

like image 79
Cristian Avatar answered Dec 10 '25 12:12

Cristian