java - Android- Logic behind setOnClickListener -
i new java/android programming , unfortunately don't under stand logic behind piece of code:
button.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { // perform action on click } });
i have alredy read whole lot of tutorials unfortunately in no 1 far code gets explained in detail. maybe because it's basic every decent object oriented programmer understand reason structure right away.
i wondering why need use new view.onclicklistener()
as parameter? setonclicklistener
method. in other words why doesn't like
button.setonclicklistener( public void onclick(view v) { // perform action on click });
this work?
besides not quite sure why onclick
method requires paramterer of view v
.
i quite thankful since rather puzzled.
view.onclicklistener
interface need implement when want handle click events. in code, doing doing new view.onclicklistener()
. here creating anonymous class implements view.onclicklistener
. , class implements view.onclicklistener
must implement methods declared in (e.g. onclick
method). also, in public void onclick(view v) {..}
, view v
denotes view or button clicked can perform whatever want it. example, it's id, change it's color etc.
Comments
Post a Comment