【发布时间】:2020-10-30 05:12:48
【问题描述】:
我想让用户能够在我的应用程序中从一个活动拖动到另一个活动,但未检测到放置事件
在第一个活动中开始拖动操作:
public boolean onItemLongClick(AdapterView<?> aParent, View aView, int aPos, long aID) {
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(aView);
Intent intent = new Intent();
intent.putExtra("Phase", "Phase");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
aView.startDragAndDrop(ClipData.newIntent(DRAG_N_DROP_DESCRIPTION, intent), shadowBuilder, null, 0);
} else {
aView.startDrag(ClipData.newIntent(DRAG_N_DROP_DESCRIPTION, intent), shadowBuilder, null, 0);
}
startSecondActivity();
finish();
return true;
}
在第二个activity中接收drop操作
public boolean onDrag(View aView, DragEvent aEvent) {
switch (aEvent.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
This is not called on Android 22+
break;
case DragEvent.ACTION_DROP:
This is not called on Android 22+
break;
}
return true;
}
解决方案将获得50分奖励。
【问题讨论】:
-
有什么建议或解释吗?
-
请参考此github.com/android/user-interface-samples/tree/main/… 示例。你可能会有一些想法。
标签: android drag-and-drop