I believe that the inclusion of android:onClick
has been a very bad idea.
- You are coupling presentation with logic
- Unless you are using a plugin that supports it, you will have to remember to refactor the xml file if you decide to change your method name
- It's just not clear the relationship between a button in your xml and a method in your activity that reacts to the click events unless you explicitly see it defined in your Java file. With the
android:onClick
approach you can even forget that you have a button in your layout or which is the method that is handling its onClick
event.
I would suggest you stick to defining your OnClickListener
s programatically and keep a strict separation of concerns, as Corey Sunwold pointed out in his comment.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…