1

所以我有一个 onClickListener 来启动一个计时器。我添加了播放android“点击”声音的代码,但有时当按下视图时,声音会作为“点击点击”多次播放。点击事件生成的信息被保存到一个文件中,我没有收到那里多次点击的证据,但我确实听到了声音。我在我的 if 语句中移动了声音,这稍微解决了这个问题,但仍然存在一些多次点击。似乎它们通常发生在用我的手指垫与尖端按压时。

public OnClickListener lapListener = new OnClickListener() 
{    
    @Override
    public void onClick(View view) {

       //if new timer = 0 the timer is not running. Start the clock, and make necessary changes
       if(newTimer == 0)
       {
           view.playSoundEffect(android.view.SoundEffectConstants.CLICK);
            startTime = SystemClock.uptimeMillis();
            customHandler.postDelayed(updateTimerThread, 0);
            customHandler.postDelayed(updateLapThread, 0);
            newTimer = 1;
            running = 1;
            stopButton.setText("Stop"); 
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
       }
       //if newtimer = 1 and running = 1 the timer is going and the user wishes to end the current lap
       else if (newTimer == 1 && running == 1)
       {

           view.playSoundEffect(android.view.SoundEffectConstants.CLICK);
           customHandler.removeCallbacks(updateLapThread);
           finishLap();
           customHandler.postDelayed(updateLapThread, 5000);


       }
       else
       {
             //Do nothing   
       }


   }
};
4

0 回答 0