Monday, January 28, 2019
Sometimes you may need to have a click and a long click (press) on the same View, here is how you can avoid triggering both event.
//button view
button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //your code here } });button.setOnLongClickListener(new View.OnLongClickListener() {@Override public boolean onLongClick(View v) { //your code here return true; } });
By setting onLongClick return to true, you are telling the compiler that you have handled onLongClick event, no need to trigger the onClick event.