Android 为什么onDrag方法运行数百万次?
我试图在我的项目中实现一个小小的拖放系统,到目前为止,我已经:Android 为什么onDrag方法运行数百万次?,android,Android,我试图在我的项目中实现一个小小的拖放系统,到目前为止,我已经: @Override public boolean onDrag(View eventView, DragEvent event) { final int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: DragAndDropState.itWasDropped =
@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,通过一次长点击触发,并在一个目标视图上使用一次长点击列表
有谁能解释我为什么会这样,或者为什么这样好
我真的很想只做其中一件事,用这样的消息充斥logcat纯粹是一种注释,我无法用这样的方式进行调试。代码中的break语句在哪里。它应该在操作之前出现。@hamad如果有返回,您不需要中断。请提供更多的代码,以便我们能够很好地理解它。。!!!