我的計時器有問題。之後,我按下從處理程序顯示的-22406914:0-51開始按鈕值而不是倒計時。下面是代碼(我幫助自己的這個幫助:http://android-developers.blogspot.com/2007/11/stitch-in-time.html)。我不知道在哪裏我犯了一個錯誤......定時器錯誤倒計時
public class biegi extends Activity {
TextView Todleglosc, Tpredkosc, Tczas;
ImageView Ibiegacz;
Button clear, startstop;
LocationManager locationManager;
Location lokacjaPoczatkowa;
String providerName;
boolean start;
private long startTime;
private Handler mHandler = new Handler();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.biegi);
inicjuj();
actionbuttonsc();
} // oncreate
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
final long start = startTime;
long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis/1000);
int minutes = seconds/60;
seconds = seconds % 60;
if (seconds < 10) {
Tczas.setText("" + minutes + ":0" + seconds);
} else {
Tczas.setText("" + minutes + ":" + seconds);
}
mHandler.postAtTime(this,start + (((minutes * 60) + seconds + 1) * 1000));
}
};
public void inicjuj(){
Todleglosc=(TextView) findViewById(R.id.odleglosc);
Tpredkosc=(TextView) findViewById(R.id.predkosc);
Tczas=(TextView) findViewById(R.id.czas);
Ibiegacz=(ImageView) findViewById(R.drawable.biegacz);
clear=(Button) findViewById(R.id.clear);
startstop=(Button) findViewById(R.id.button_bieg_start_stop);
start=false;
}
public void actionbuttonsc()
{
clear.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Tczas.setText("00:00:00");
}
});
startstop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (start==false)
{
Tczas.setText("00:00:01");
startTime = System.currentTimeMillis();
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(mUpdateTimeTask, 100);
start=true;
}
else if (start==true)
{
Tczas.setText("00:00:00");
mHandler.removeCallbacks(mUpdateTimeTask);
start=false;
}}});
}
}
你可以打印出你的啓動變量,並告訴我們它是什麼,以便更容易地告訴究竟是怎麼回事? – Michael 2012-08-08 20:53:49