fkmさん、こんばんは。
早速の返信ありがとうございます。
以下が現在書いている試作コードなのですが、アドバイスいただいた内容をどこに入れればよいかわかりません。
重ね重ね恐縮ですが、ご教示いただけますでしょうか。
-----以下、試作コード
package test.stopwatch.v2;
import java.math.BigDecimal;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Test_stopwatch_v2Activity extends Activity implements
OnClickListener{
TextView mTextView;
Button mStartBtn, mStopBtn;
float mLaptime = 0.00f;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//IDの取得
mTextView = (TextView) findViewById(R.id.LapTime);
mStartBtn = (Button) findViewById(R.id.StartBtn);
mStopBtn = (Button) findViewById(R.id.StopBtn);
mStartBtn.setOnClickListener(this);
mStopBtn.setOnClickListener(this);
}
class MyTimerTask extends TimerTask{
@Override
public void run() {
// mHandlerを通じてUI Threadへ処理をキューイング
mHandler.post( new Runnable() {
public void run() {
//実行間隔分を加算処理
mLaptime += 0.01d;
//計算にゆらぎがあるので小数点第2位で丸める
BigDecimal bi = new BigDecimal(mLaptime);
float outputValue = bi.setScale(2,
BigDecimal.ROUND_HALF_UP).floatValue();
//現在のLapTime
mTextView.setText(Float.toString(outputValue));
}
});
}
}
MyTimerTask timerTask = null;
Timer mTimer = null;
Handler mHandler = new Handler();
public void onClick(View v){
Button btn = (Button)v;
switch( btn.getId() ){
//スタートボタンが押されたとき
case R.id.StartBtn:
if(mTimer == null){
//タイマーの初期化処理
timerTask = new MyTimerTask();
mLaptime = 0.00f;
mTimer = new Timer(true);
mTimer.schedule( timerTask, 10, 10);
}
break;
//ストップボタンが押されたとき
case R.id.StopBtn:
if(mTimer != null){
mTimer.cancel();
mTimer = null;
}
break;
default:
break;
}
}
}
------ここまで
On 4月10日, 午前12:21, Hirokazu Fukami <
fkm...@gmail.com> wrote:
> こんばんはfkmです。
>
> Android上で動かしてないのでだめかもですが、こんな感じでしょうか?
>
> Date date = new Date(1238877); // 単位はミリ秒
> SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss.SS");
> System.out.println(format.format(date));
>
> 2012/4/10 hirosasemashi <
masasehiroshi1...@gmail.com>:
>
f_hy...@hotmail.co.jp
>
fkm...@gmail.com