@OverrIDepublic boolean onDrag(VIEw v,DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_ENTERED: switch (v.getID()) { case R.ID.delete_zone: { addToShowCaseZone.setimageDrawable(getResources().getDrawable(R.drawable.showcase_2)); inAddToShowcasesZone = true; break; } case MagazineGrIDAdapter.ID: { enteredVIEw = v; break; } } return false; case DragEvent.ACTION_DRAG_EXITED: { switch (v.getID()) { case R.ID.delete_zone: { addToShowCaseZone.setimageDrawable(getResources().getDrawable(R.drawable.showcase_1)); inAddToShowcasesZone = false; break; } case MagazineGrIDAdapter.ID: { enteredVIEw = null; break; } } return true; } case DragEvent.ACTION_DRAG_STARTED: return true; case DragEvent.ACTION_DRAG_LOCATION: return false; case DragEvent.ACTION_DROP: { if (inAddToShowcasesZone) { final int position = grIDVIEw.getpositionForVIEw(dragVIEw); Magazine magazine = magazineAdapter.getItem(position); try { new Magazine(magazine.getUrl().toString(),magazine.getimage(),magazine.getBackgroundNum(),magazine.getname()); } catch (MalformedURLException e) { e.printstacktrace(); } addToShowCaseZone.setimageDrawable(getResources().getDrawable(R.drawable.showcase_1)); inAddToShowcasesZone = false; magazineAdapter.deleteFromList(position); return false; } else if(enteredVIEw != null && !enteredVIEw.equals(dragVIEw)){ ResourcesForNativeMagazines.swAPItems(grIDVIEw.getpositionForVIEw(dragVIEw),grIDVIEw.getpositionForVIEw(enteredVIEw),tabNumber - 1); magazineAdapter.refreshValues(ResourcesForNativeMagazines.getMagazines(tabNumber - 1)); enteredVIEw = null; return false; } dragVIEw.setVisibility(VISIBLE); return false; } default: dragVIEw.setVisibility(VISIBLE); return true; }}
适配器部件:
public voID refreshValues(List<Magazine> magazines){ this.magazines = new ArrayList<>(magazines); notifyDataSetChanged();}public voID deleteFromList(int position){ magazines.remove(position); notifyDataSetChanged();}
有时这个代码在我删除项目时调用方法refreshValuews和deleteFromList中的错误,这是它的堆栈跟踪:
java.util.ConcurrentModificationException at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806) at java.util.HashMap$KeyIterator.next(HashMap.java:833) at androID.vIEw.VIEwGroup.dispatchDragEvent(VIEwGroup.java:1172) at androID.vIEw.VIEwGroup.dispatchDragEvent(VIEwGroup.java:1174) at androID.vIEw.VIEwGroup.dispatchDragEvent(VIEwGroup.java:1174) at androID.vIEw.VIEwGroup.dispatchDragEvent(VIEwGroup.java:1174) at androID.vIEw.VIEwGroup.dispatchDragEvent(VIEwGroup.java:1174) at androID.vIEw.VIEwGroup.dispatchDragEvent(VIEwGroup.java:1174) at androID.vIEw.VIEwGroup.dispatchDragEvent(VIEwGroup.java:1174) at androID.vIEw.VIEwRootImpl.handleDragEvent(VIEwRootImpl.java:4911) at androID.vIEw.VIEwRootImpl.access0(VIEwRootImpl.java:94) at androID.vIEw.VIEwRootImpl$VIEwRootHandler.handleMessage(VIEwRootImpl.java:3188) at androID.os.Handler.dispatchMessage(Handler.java:99) at androID.os.Looper.loop(Looper.java:137) at androID.app.ActivityThread.main(ActivityThread.java:5103) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)
我应该怎么解决?有没有其他方法可以通过拖放来修改grIDVIEw中的项目?
解决方法 我找到了一个解决方案,不要引起你应该做的下一个例外:public boolean onDrag(VIEw v,DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_ENDED:{ v.post(new Runnable{ public voID run() { //SomeCode; } }); break; } }}总结
以上是内存溢出为你收集整理的android – Drag’n’Drop ConcurentModificationException全部内容,希望文章能够帮你解决android – Drag’n’Drop ConcurentModificationException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)