Onlongclicklistener Not Working In Custom Framelayout Android
I have an ImageView in a FrameLayout, I want to setup LongClickListener but its failing to work, I tried setting up OnTouchListener and its working flawless, I do not have the slig
Solution 1:
I want to setup LongClickListener but its failing to work
You are not receiving the callbacks from OnLongClickListener
because it has no set listener. Since your class implements View.OnLongClickListener
and you want to receive the callback in your overridden onLongClick()
method, add this class itself as the listener and it will work. I've done so in the constructor (choose the appropriate constructor out of the three as per your initialization of the view):
public DragImageView(Context context, AttributeSet attrs) {
super(context, attrs);
this.setOnLongClickListener(this); // <-- set this class instance as the listener
}
Although I'm surprised how you got it working with OnTouchListener
. You probably explicitly added the listener, right?
Post a Comment for "Onlongclicklistener Not Working In Custom Framelayout Android"