Search code examples
androidandroid-buttonandroid-custom-viewbuttonclick

Android custom button generic click handler


i'm trying to implement a custom button which allows me to execute a standard set of actions when the button is clicked (such as writing a log) plus executing the assigned click listener specific for every instance of the button. IS that possibile?

Many thanks


Solution

  • Solution found, in this way for every instance of the button i can do a standard set of actions (in this case it's just writing a log) before executing the specified click listener

    @Override
        public void setOnClickListener(final OnClickListener l) {
    
            super.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    LogHelper.WriteLogInfo("click");
                    l.onClick(v);
    
                }
            });
        }