Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
multiple OnClickListeners in one Android control (java class)
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
* Created by kosiara on 9/20/15.
public class DoubleClickListenerImageButton extends ImageButton {
View.OnClickListener mSecondOnClickListener;
public DoubleClickListenerImageButton(Context context) {
public DoubleClickListenerImageButton(Context context, AttributeSet attrs) {
super(context, attrs);
public DoubleClickListenerImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
public DoubleClickListenerImageButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
public void setSecondOnClickListener(View.OnClickListener l) {
mSecondOnClickListener = l;
public boolean performClick() {
if (mSecondOnClickListener != null)
return super.performClick();
public boolean performContextClick() {
if (mSecondOnClickListener != null)
return super.performContextClick();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.