Android拖放:多个视图报告拖放?
我似乎不理解Android的拖放功能。 我已经设置了4个独立的视图,并将它们的Android拖放:多个视图报告拖放?,android,Android,我似乎不理解Android的拖放功能。 我已经设置了4个独立的视图,并将它们的ondraglister设置为下面的代码。我希望用户将图像拖到四个视图之一上。当用户删除被拖动的图像时,我想用相关数据填充删除图像的视图 我看到的问题是,所有四个视图都在ACTION\u DRAG\u end上响应event.getResult()=true。当拖动视图进入边界区域时,只有一个视图响应。根据Android文档event.getResult()返回false,除非发送了操作。但是所有四个视图都显示了tru
ondraglister
设置为下面的代码。我希望用户将图像拖到四个视图之一上。当用户删除被拖动的图像时,我想用相关数据填充删除图像的视图
我看到的问题是,所有四个视图都在ACTION\u DRAG\u end
上响应event.getResult()=true
。当拖动视图进入边界区域时,只有一个视图响应。根据Android文档event.getResult()
返回false,除非发送了操作。但是所有四个视图都显示了true的getResult()
,只有一个视图显示了操作下拉列表(参见下面的Logcat)
Java代码
日志:
myDragListener
应该做什么不同的事情,以便只有一个视图从event.getResult()
中获得true的结果?在操作中执行更新
这就是您知道被丢弃的内容的地方(item
,注意:您还可以使用getLocalState()
传递Object
s),并知道它被丢弃的位置(onDrag
的第一个参数是dropTarget)。如果您想知道它来自何处,可以在调用view.startDrag(…,new view.DragShadowBuilder(view),view,0)
时将视图作为本地状态传递
动作拖动开始
/动作拖动结束
表示:
大家好,有人开始/完成了拖放操作(使用getResult()
result),您现在可以显示/隐藏接收拖放的能力
你可以在这里找到上面的官方措辞:真的吗?没有人有答案?只是有同样的问题。如果我知道如何解决这个问题,我会发帖的
private OnDragListener mydragListener = new OnDragListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public boolean onDrag(View v, DragEvent event) {
final int action = event.getAction();
ClipData dragData;
boolean handled = false;
switch (action) {
case DragEvent.ACTION_DRAG_STARTED: {
dragSku = event.getClipDescription().getLabel().toString();
handled = true;
Log.d(TAG,"ACTION_DRAG_STARTED="+handled);
} break;
case DragEvent.ACTION_DRAG_ENDED: {
// Report the drop/no-drop result to the user
final boolean dropped = event.getResult();
if (dropped) {
Log.d(TAG,"THIS SHOULD BE DROPPED: "+v.toString());
handled = true;
}
else {
handled = false;
}
Log.d(TAG,"ACTION_DRAG_ENDED="+handled);
} break;
case DragEvent.ACTION_DROP:
// Gets the item containing the dragged data
ClipData.Item item = event.getClipData().getItemAt(0);
// Returns true. DragEvent.getResult() will return true.
handled = true;
Log.d(TAG,"ACTION_DROP="+handled);
break;
case DragEvent.ACTION_DRAG_EXITED: {
handled = false;
Log.d(TAG,"ACTION_DRAG_EXITED="+handled);
} break;
case DragEvent.ACTION_DRAG_ENTERED: {
handled = true;
Log.d(TAG,"ACTION_DRAG_ENTERED="+handled);
}
}
return handled;
}
};
12-10 12:13:56.240: D/BrowsePhonesDevices(25667): ClipData : ClipData { text/plain "sku340603" {T:sku} } : sku340603
12-10 12:13:56.275: D/BrowsePhonesDevices(25667): ACTION_DRAG_STARTED=true
12-10 12:13:56.275: D/BrowsePhonesDevices(25667): ACTION_DRAG_STARTED=true
12-10 12:13:56.275: D/BrowsePhonesDevices(25667): ACTION_DRAG_STARTED=true
12-10 12:13:56.275: D/BrowsePhonesDevices(25667): ACTION_DRAG_STARTED=true
12-10 12:13:56.960: D/BrowsePhonesDevices(25667): ACTION_DRAG_ENTERED=true
12-10 12:13:57.205: D/BrowsePhonesDevices(25667): ACTION_DROP=true
12-10 12:13:57.205: I/ViewRootImpl(25667): Reporting drop result: true
12-10 12:13:57.215: D/BrowsePhonesDevices(25667): THIS SHOULD BE DROPPED: android.widget.ImageView@42dfa5f0
12-10 12:13:57.215: D/BrowsePhonesDevices(25667): ACTION_DRAG_ENDED=true
12-10 12:13:57.215: D/BrowsePhonesDevices(25667): THIS SHOULD BE DROPPED: android.widget.ImageView@42dee7b0
12-10 12:13:57.215: D/BrowsePhonesDevices(25667): ACTION_DRAG_ENDED=true
12-10 12:13:57.215: D/BrowsePhonesDevices(25667): THIS SHOULD BE DROPPED: android.widget.ImageView@42df7618
12-10 12:13:57.215: D/BrowsePhonesDevices(25667): ACTION_DRAG_ENDED=true
12-10 12:13:57.215: D/BrowsePhonesDevices(25667): THIS SHOULD BE DROPPED: android.widget.ImageView@42df8e48
12-10 12:13:57.215: D/BrowsePhonesDevices(25667): ACTION_DRAG_ENDED=true