onTouchEvent onClick onLongClick calls
You have to return false instead of true in OnTouch(View v,MotionEvent event) function so that other listeners on the control remains active.
According to the doc Handling UI Events,
onLongClick() - This returns a boolean to indicate whether you have consumed the event and it should not be carried further. That is, return true to indicate that you have handled the event and it should stop here; return false if you have not handled it and/or the event should continue to any other on-click listeners.
And above all about onTouch:
onTouch() - This returns a boolean to indicate whether your listener consumes this event. The important thing is that this event can have multiple actions that follow each other. So, if you return false when the down action event is received, you indicate that you have not consumed the event and are also not interested in subsequent actions from this event. Thus, you will not be called for any other actions within the event, such as a finger gesture, or the eventual up action event.
Indeed, depending on the event, you have to return the right value.
Seems like you have reference problem. Try to set click, long click and touch listener like this:
btnAdd.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
btnAdd.setOnLongClickListener(new Button.OnLongClickListener(){
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
return false;
}
});
btnAdd.setOnTouchListener(new Button.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
});
When you need both click and touch events on the same view, use a GestureDetector. It can detect long presses as well.