Android Countdown Timer禁用onItemLongClickListener

时间:2014-02-10 23:24:57

标签: android onclick countdowntimer

我对此做了一些研究,但似乎无法解决我的问题。我有一个倒数计时器,我按下按钮开始。我想在倒数计时器运行时禁用我的OnItemLongClickListener方法。当我这样做时,我得到一个空指针异常。谁会知道我哪里出错了?感谢

以下是我正在使用的代码:

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

        list.setOnItemLongClickListener(null);
        tvStart = (TextView) findViewById( R.id.tvStart);

        new CountDownTimer(20000, 1000) {

        public void onTick(long millisUntilFinished) {
               tvStart.setText("Time remaining: " +new SimpleDateFormat("mm:ss").format(new Date( millisUntilFinished)));

 }

public void onFinish() {
           tvStart.setText("Select new positions");

        mHandler.postDelayed(mUpdateTimeTask, 1000);

}
}.start();

};


OnItemLongClickListener longListen = new OnItemLongClickListener(){

    @Override
    public boolean onItemLongClick(AdapterView<?> arg0, View v,
            int pos, long id){

        DragShadow dragShadow = new DragShadow(v);

        ClipData data = ClipData.newPlainText("", "");
        v.startDrag(data, dragShadow, v, 0);
 }

02-11 00:13:02.746: E/AndroidRuntime(1490): FATAL EXCEPTION: main
02-11 00:13:02.746: E/AndroidRuntime(1490): java.lang.NullPointerException
02-11 00:13:02.746: E/AndroidRuntime(1490):     at com.example.gogamesapp.Positions$3.onClick(Positions.java:115)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at android.view.View.performClick(View.java:4204)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at android.view.View$PerformClick.run(View.java:17355)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at android.os.Handler.handleCallback(Handler.java:725)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at android.os.Looper.loop(Looper.java:137)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at android.app.ActivityThread.main(ActivityThread.java:5041)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at java.lang.reflect.Method.invokeNative(Native Method)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at java.lang.reflect.Method.invoke(Method.java:511)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-11 00:13:02.746: E/AndroidRuntime(1490):     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案