How to create our own Listener interface in android?

前端 未结 9 1922
不知归路
不知归路 2020-11-22 04:55

Could someone help me to create user defined listener interface with some code snippets?

9条回答
  •  遇见更好的自我
    2020-11-22 05:48

    Create listener interface.

    public interface YourCustomListener
    {
        public void onCustomClick(View view);
                // pass view as argument or whatever you want.
    }
    

    And create method setOnCustomClick in another activity(or fragment) , where you want to apply your custom listener......

      public void setCustomClickListener(YourCustomListener yourCustomListener)
    {
        this.yourCustomListener= yourCustomListener;
    }
    

    Call this method from your First activity, and pass the listener interface...

提交回复
热议问题