我尝试在我的项目中实现一个小拖放系统,到目前为止我有:
@Override
public boolean onDrag(View eventView, DragEvent event) {
final int action = event.getAction();
switch (action) {
case DragEvent.ACTION_DRAG_STARTED:
DragAndDropState.itWasDropped = false;
draggedView = (View) event.getLocalState();
if (draggedView.getParent() != null) {
draggedTargetParent = (View) draggedView.getParent();
DragAndDropState.dragStartPosition = (Integer) draggedTargetParent.getTag();
Log.i("START draggedView ", draggedView.toString());
Log.i("START parent: ", draggedTargetParent.toString());
}
((ViewGroup) eventView).removeView((View) event.getLocalState());
return true;
case DragEvent.ACTION_DROP: //............... more code
在我长按视图后,我在 logcat 中看到:
09-03 14:08:48.236: I/START draggedView(12796): hu.fun.views.slot.ItemInSlotView@42ae2ef0
09-03 14:08:48.236: I/START parent:(12796): hu.fun.views.slot.Slot@42ab7e68
09-03 14:08:48.236: I/START draggedView(12796): hu.fun.views.slot.ItemInSlotView@42ae2ef0
09-03 14:08:48.236: I/START parent:(12796): hu.fun.views.slot.Slot@42ab7e68
09-03 14:08:48.236: I/START draggedView(12796): hu.fun.views.slot.ItemInSlotView@42ae2ef0
09-03 14:08:48.236: I/START parent:(12796): hu.fun.views.slot.Slot@42ab7e68
09-03 14:08:48.236: I/START draggedView(12796): hu.fun.views.slot.ItemInSlotView@42ae2ef0
09-03 14:08:48.246: I/START parent:(12796): hu.fun.views.slot.Slot@42ab7e68
09-03 14:08:48.246: I/START draggedView(12796): hu.fun.views.slot.ItemInSlotView@42ae2ef0
09-03 14:08:48.246: I/START parent:(12796): hu.fun.views.slot.Slot@42ab7e68
09-03 14:08:48.246: I/START draggedView(12796): hu.fun.views.slot.ItemInSlotView@42ae2ef0
09-03 14:08:48.246: I/START parent:(12796): hu.fun.views.slot.Slot@42ab7e68
09-03 14:08:49.137: I/ViewRootImpl(12796): Reporting drop result: true
没错。我得到了 6 个(六个!) onDragEvents由一个 longclick触发,一个 onLongClick 侦听器在一个 View 目标上。
任何人都可以解释我为什么会这样,或者为什么它很好?
我真的很想只处理其中的一个,用这样的消息淹没 logcat 真是太烦人了,我无法调试这样的方式。