为什么Postdelayed不在if语句中工作

当我把postDelayed(this,1000);时,为什么计时器停止工作postDelayed(this,1000); 在if语句中,只需seconds++; ? 布局中有3个按钮(开始,停止,重置)。 按Start-> running = true,按stop-> running = stop,按reset-> running = false seconds = 0

 private void runTimer() { final TextView timeView = (TextView) findViewById(R.id.time_view); final Handler handler = new Handler(); handler.post(new Runnable() { @Override public void run() { int hours = seconds / 3600; int minutes = (seconds % 3600) / 60; int secs = seconds % 60; String time = String.format("%d:%2d:%02d", hours, minutes, secs); timeView.setText(time); if (running) { seconds++; //handler.postDelayed(this, 1000); //doesnt work if i put it here } handler.postDelayed(this, 1000); } }); } 

在调用runTimer()running的变量设置为false。 很可能你必须将runTimer()的调用移动到onClickStart()方法(在设置运行为true之后)。
声明布尔值时,默认值为false。