我在 ListFragment 中使用拖动排序列表视图( https://github.com/bauerca/drag-sort-listview )。
当我在创建时启用拖动排序时,一切正常。但是,我想让它保持禁用状态,直到长按列表视图中的一项。
所以我想设置
mDslv.setDragEnabled(false);
在 3 个地方:onCreateView()、DragSortListView.DropListener 和 DragSortListView.RemoveListener
在我的 ListFragment 中,我有:
listView.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
mDslv.setDragEnabled(true);
return true;
}
});
我希望长按任何项目将打开 DSLV 并允许删除或删除该项目,之后将再次禁用 DSLV。
但是,在调用 setDrageEnabled(true) 之后(不是同时),我得到一个 NullPointerException:
09-03 00:03:33.749: E/AndroidRuntime(9703): FATAL EXCEPTION: main
09-03 00:03:33.749: E/AndroidRuntime(9703): java.lang.NullPointerException
09-03 00:03:33.749: E/AndroidRuntime(9703): at com.mobeta.android.dslv.DragSortController.onScroll(DragSortController.java:381)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:541)
09-03 00:03:33.749: E/AndroidRuntime(9703): at com.mobeta.android.dslv.DragSortController.onTouch(DragSortController.java:243)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.View.dispatchTouchEvent(View.java:3881)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
09-03 00:03:33.749: E/AndroidRuntime(9703): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1703)
09-03 00:03:33.749: E/AndroidRuntime(9703): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1133)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
09-03 00:03:33.749: E/AndroidRuntime(9703): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1687)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2196)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.view.ViewRoot.handleMessage(ViewRoot.java:1880)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.os.Looper.loop(Looper.java:130)
09-03 00:03:33.749: E/AndroidRuntime(9703): at android.app.ActivityThread.main(ActivityThread.java:3729)
09-03 00:03:33.749: E/AndroidRuntime(9703): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 00:03:33.749: E/AndroidRuntime(9703): at java.lang.reflect.Method.invoke(Method.java:507)
09-03 00:03:33.749: E/AndroidRuntime(9703): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
09-03 00:03:33.749: E/AndroidRuntime(9703): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
09-03 00:03:33.749: E/AndroidRuntime(9703): at dalvik.system.NativeStart.main(Native Method)
有没有人试过这个?有任何想法吗?看起来其中一个运动事件为 NULL,可能是因为我在触摸事件期间启用了 DSLV。