Android: how to handle button click

后端 未结 10 2166
刺人心
刺人心 2020-11-27 11:08

Having a solid experience in non-Java and non-Android area, I\'m learning Android.

I have a lot of confusion with different areas, one of them is how to handle butt

10条回答
  •  有刺的猬
    2020-11-27 11:26

    Question#1 - These are the only way to handle view clicks.

    Question#2 -
    Option#1/Option#4 - There's not much difference between option#1 and option#4. The only difference I see is in one case activity is implementing the OnClickListener, whereas, in the other case, there'd be an anonymous implementation.

    Option#2 - In this method an anonymous class will be generated. This method is a bit cumborsome, as, you'd need to do it multiple times, if you have multiple buttons. For Anonymous classes, you have to be careful for handling memory leaks.

    Option#3 - Though, this is a easy way. Usually, Programmers try not to use any method until they write it, and hence this method is not widely used. You'd see mostly people use Option#4. Because it is cleaner in term of code.

提交回复
热议问题