DragLinearLayout
DragLinearLayout copied to clipboard
Enable Dragging on only Long Click
enabling drag on long click is not available and no callback method for ondragstop.
I found a simple solution to this.
- Add a boolean to DragLinearLayout
static boolean canDrag = false
- In setViewDraggable, add an onLongClickListener to the new view that simply does
dragHandle.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
canDrag = true;
return false;
}
});
- Replace all instances of
startDrag()
with:
if (canDrag) {
startDrag();
return true;
}
- In
startDrag()
ANDonTouchEnd()
add
canDrag = false
Basically, if the view being touched has also been long clicked then carry out activities as normal. I also removed the slop check in ACTION_MOVE because it was extremely difficult to do.
Sorry about the formatting. I made an account to write this comment.
@idelder I have applied the code you have suggested but drag is not working onLong press.
Timer may helps