我尝试在我的项目中实施一些拖放系统,到目前为止我已经:
@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个(6个!) onDragEvents,在一个有针对性的视图上用一个onLongClick侦听器触发了一个longclick 。
任何人都可以解释我为什么会这样,或者为什么这么好?
我真的只想使用这些东西中的一个,这对于使用这样的消息来淹没logcat是纯粹的反感。我无法调试这样的方式。