Android - 滚动时禁用触摸事件

时间:2011-12-22 16:30:57

标签: android

我尝试了各种各样的解决方法,但没有一个对我有用。我有一个包含单元格的scrollview,每个单元格都有一个onclicklistener。这些onclicklisteners将视图添加到主视图中,并清除这些子视图onscrollchanged。但如果我尝试在使用fling动作滚动时单击这些单元格,则应用程序崩溃。我尝试在try catch块中添加视图,但异常没有被捕获,应用程序崩溃了..

所以我想在滚动过程中禁用触摸事件。有没有办法做到这一点? 崩溃日志如下: -

12-22 13:25:34.420: DEBUG/FlurryAgent(7877): Error logged: uncaught
12-22 13:25:34.430: ERROR/AndroidRuntime(7877): FATAL EXCEPTION: main
12-22 13:25:34.430: ERROR/AndroidRuntime(7877): java.lang.NullPointerException
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2188)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.View.draw(View.java:9282)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.drawChild(ViewGroup.java:2584)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2189)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.drawChild(ViewGroup.java:2582)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2189)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.drawChild(ViewGroup.java:2582)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2189)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.drawChild(ViewGroup.java:2582)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2189)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.drawChild(ViewGroup.java:2582)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2189)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.View.draw(View.java:9282)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.widget.FrameLayout.draw(FrameLayout.java:419)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1924)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewRoot.draw(ViewRoot.java:1666)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1381)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.view.ViewRoot.handleMessage(ViewRoot.java:2003)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.os.Looper.loop(Looper.java:132)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at android.app.ActivityThread.main(ActivityThread.java:4025)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at java.lang.reflect.Method.invokeNative(Native Method)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at java.lang.reflect.Method.invoke(Method.java:491)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
12-22 13:25:34.430: ERROR/AndroidRuntime(7877):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

假设我们有2个事件,event1和event2,并且当调用event1时,它将调用event2。所以你想禁用event2? 一般来说,我通常会创建一个变量

  

isDisable = false

然后覆盖事件2并以某种方式将isDisable传递给event2,假设我们将isDisable传递给event2,然后关于event1的代码应该是

isDisable = true;
call event2
isDisable = false;

并且在event2中,你必须检查isDisable = true或false来决定调用event2做什么。