0

我从一个计时器网站获得此代码我想在我的活动开始时运行计时器并且我想以整数值接收以秒为单位的运行时间

          myclock =  mChronometer.get vaule (example idea);

或任何其他可以直接从计时器中获取价值的方法

 import android.app.Activity;
  import android.os.Bundle;
  import android.os.SystemClock;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.Chronometer;

  public class StopWatch extends Activity {
Chronometer mChronometer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    Button button;

    mChronometer = (Chronometer) findViewById(R.id.chronometer);

    // Watch for button clicks.
    button = (Button) findViewById(R.id.start);
    button.setOnClickListener(mStartListener);

    button = (Button) findViewById(R.id.stop);
    button.setOnClickListener(mStopListener);

    button = (Button) findViewById(R.id.reset);
    button.setOnClickListener(mResetListener);

}

View.OnClickListener mStartListener = new OnClickListener() {
    public void onClick(View v) {
        mChronometer.start();
    }
};

View.OnClickListener mStopListener = new OnClickListener() {
    public void onClick(View v) {
        mChronometer.stop();
    }
};

View.OnClickListener mResetListener = new OnClickListener() {
    public void onClick(View v) {
        mChronometer.setBase(SystemClock.elapsedRealtime());
    }
};
}     

提前感谢你们帮助我这里是原始网站的链接 http://www.edumobile.org/android/android-development/stop-watch-example/

4

0 回答 0