2014-11-01 42 views
0

我已經來到這裏這個函數中執行一個功能:定時器

public void stoprecording() 
{ 
    this.recorder.stop(); 
    this.recorder.reset(); 
    this.recorder.release(); 
} 

其停止recoridng。這是類Audio內的。我也在這裏得到這個功能:

public void recordtimer(final int timer) 
{ 
    /*First Part with timer*/ 
    Thread thread = new Thread(new Runnable() 
    { 
     @Override 
     public void run() 
     { 
      CountDownTimer countDowntimer = new CountDownTimer(timer, 100000) 
      { 
       public void onTick(long millisUntilFinished) {} 

       public void onFinish() { 

        this.stoprecording(); 
       } 
      };countDowntimer.start(); 
     } 
    }); 

    thread.start(); 

    this.stoprecording(); 
} 

也在類音頻。我不能執行this.stoprecording();因爲CountDownTimer類沒有這個函數。我怎樣才能執行這個功能?

+1

嘗試'Classname.this.methodname();'。如果你的班級名稱是'Audio',你必須寫'Audio.this.stoprecording();'。 – 2014-11-01 22:50:32

回答

0

看着你的代碼,似乎沒有必要從this調用stoprecording(),因爲它不屬於你定義的CountDownTimer類。

就這樣稱呼它

public void onFinish() { 

    stoprecording(); 
} 

,或者如果你想肯定要用到this,遵循@ gary111建議這樣做

public void onFinish() { 

    YourClass.this.stoprecording(); 
}