我有一個應用程序,告訴我在學校需要多少小時(:P)。我有一個textview文本時間:(小時去)。這應該是6.2,但現在是6,然後當我點擊開始時,它說學校立即完成,然後崩潰。哦,我想以幾小時的時間顯示時間,就像這樣(6.2 = 6小時20分鐘)。 可能是什麼問題?Android倒數計時器崩潰和錯誤的值
代碼startActivity:
package com.nieeli.timer;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class startActivity extends Activity implements OnClickListener {
private static final String tag = "Main";
private MalibuCountDownTimer countDownTimer;
private long timeElapsed;
private boolean timerHasStarted = false;
private Button startB;
private TextView text;
private TextView timeElapsedView;
private final long startTime = 22500000/3600000;
private final long interval = 1/100;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startB = (Button) this.findViewById(R.id.button);
startB.setOnClickListener(this);
text = (TextView) this.findViewById(R.id.timer);
timeElapsedView = (TextView) this.findViewById(R.id.timeElapsed);
countDownTimer = new MalibuCountDownTimer(startTime, interval);
text.setText(text.getText() + String.valueOf(startTime));
}
public void onClick(View v) {
if (!timerHasStarted) {
countDownTimer.start();
timerHasStarted = true;
startB.setText("Start");
} else {
countDownTimer.cancel();
timerHasStarted = false;
startB.setText("Stop and Reset");
}
}
// CountDownTimer class
public class MalibuCountDownTimer extends CountDownTimer {
public MalibuCountDownTimer(long startTime, long interval) {
super(startTime, interval);
}
@Override
public void onFinish() {
text.setText("School Finished!");
timeElapsedView.setText("Time Passed: "
+ String.valueOf(startTime));
}
@Override
public void onTick(long millisUntilFinished) {
text.setText("Time remain:" + millisUntilFinished);
timeElapsed = startTime - millisUntilFinished;
timeElapsedView.setText("Time Left: "
+ String.valueOf(timeElapsed));
}
}
}
未作艙單或佈局的任何變化。
感謝:D
張貼您的logcat –
你有嘗試後評論timeElapsedView.setText(「時間流逝:」 + String.valueOf(startTime)); 行? –
我找不到有關我的應用的任何logcat消息,它們都來自系統o.o – Niell