我尝试在2个网格视图之间拖放项目,当我删除它时,项目正确添加到目标列表但它没有从源列表中删除。 这是我的功能
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DROP:
PassObject passObj = (PassObject)event.getLocalState();
View view = passObj.view;
Artifact passedItem = passObj.artifact;
List<Artifact> srcList = passObj.srcList;
AbsListView oldParent = (AbsListView)view.getParent();
ArtifactAdapter srcAdapter = (ArtifactAdapter) oldParent.getAdapter();
LinearLayoutAbsListView newParent = (LinearLayoutAbsListView)v;
ArtifactAdapter destAdapter = (ArtifactAdapter)(newParent.absListView.getAdapter());
List<Artifact> destList = destAdapter.getList();
srcList.remove(passedItem);
addItemToList(destList, passedItem);
srcAdapter.notifyDataSetChanged();
destAdapter.notifyDataSetChanged();
//smooth scroll to bottom
newParent.absListView.smoothScrollToPosition(destAdapter.getCount()-1);
break;
return true;
}
};
有人可以帮助我
答案 0 :(得分:0)
制作case DragEvent.ACTION_DRAG_ENDED:
,然后从原始网格中删除该项目。从具有不同上下文的其他网格视图调用ACTION_DROP
。
如果您100%确定当前ACTION_DRAG_STARTED
被解雇,则需要使用ACTION_DRAG_STARTED
取消该项目。
请记住哪个元素在哪个上下文中使用适配器。您的电话srcList.remove(passedItem);
可能不在正确的背景下(活动,片段,片段活动......等)