I am trying to implement OnClick
behaviour on my application view. As I am new to android and will like to know if passing this to while implementing View.OnClickListener
interface will be better choice or using setOnclickListener
Anonymous class to widget. As to me what I feel is that passing this may cause the whole activity and its child elements to the particular widget so having more memory consumption and so to avoid memory leak which is the best approach to go with.
setOnclickListener vs Activity implements View.OnClickListener
510 views Asked by Mehvish Ali At
2
Actually when we implement OnClickListener because we have more than one or two click item. like if i have 10 buttons in a single layout and i write each click listener as:
Its not a good programming practice thats why we implement OnClickListener and write all the click listeners in onClick(). so it looks easy to you for making any changes in future.
else if you have single button then you can use setOnClickListener().
There is not too much difference between these two. Its all about good coding practice in android. :)