DragLinearLayout icon indicating copy to clipboard operation
DragLinearLayout copied to clipboard

Enable Dragging on only Long Click

Open Raminishekhar opened this issue 7 years ago • 3 comments

enabling drag on long click is not available and no callback method for ondragstop.

Raminishekhar avatar Sep 05 '17 08:09 Raminishekhar

I found a simple solution to this.

  1. Add a boolean to DragLinearLayout

static boolean canDrag = false

  1. 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; } });

  1. Replace all instances of startDrag() with:

if (canDrag) { startDrag(); return true; }

  1. In startDrag() AND onTouchEnd() 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 avatar Jan 22 '18 19:01 idelder

@idelder I have applied the code you have suggested but drag is not working onLong press.

himanshu1706 avatar Apr 03 '18 05:04 himanshu1706

Timer may helps

devishell avatar Oct 31 '18 09:10 devishell