java - OnClickListener doesn't work implicitly. Why? -


i created custom button class implements listener interface:

public class blinkbutton  extends button implements view.onclicklistener {  list<onclicklistener> onclicklistenerlist = new arraylist<onclicklistener>();  public blinkbutton(context context) {     super(context);     this.setlistener(new highlightbuttonlistener()); }  //other constructors here   public void setlistener(onclicklistener listener){     onclicklistenerlist.add(listener); }  @override public void onclick(view v) {     for(onclicklistener listener : onclicklistenerlist){         listener.onclick(this);     } } 

and have view:

   <com.example.element.blinkbutton     .../> 

i claim onclick method inside com.example.element.blinkbutton should call implicitly when user clicks blinkbutton, it's not. have write explicitly: android:onclick="fireevent" ,

    public void fireevent(view view) {         fireeventbutton.onclick(view);     }   

why blinkbutton.onclick(); doesn't trigger automatically once user clicks button?

button (or superclasses) don't have onclick() method itself. 1 implement comes view.onclicklistener interface button class implements.

you never set class' onclicklistener, , code seems want onclicklistener class itself, custom listeners called.

add line constructor:

setonclicklistener(this); 

so looks this:

public blinkbutton(context context) {     super(context);     setonclicklistener(this);     this.setlistener(new highlightbuttonlistener()); } 

you'll have remove onclick xml attribute.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -