Android时分秒计时器

新人报道!!!


@Override
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timer = (Chronometer) findViewById(R.id.timer);
}
public void btnClick(View view) {
timer.setBase(SystemClock.elapsedRealtime()); //计时器清零
int hour = ( int ) ((SystemClock.elapsedRealtime() - timer.getBase()) / 1000 / 60 );
timer.setFormat( "0" +String.valueOf(hour)+ ":%s" );
timer.start();
}
public void stopClick(View view) {
timer.stop();
}
XML 文件:

android:layout_width= "match_parent"
android:layout_height= "wrap_content"
android:format= "00:00:00"
android:gravity= "center"
android:id= "@+id/timer" />

参考:http://www.jb51.net/article/91172.htm


你可能感兴趣的:(Android时分秒计时器)