android:format;//定义时间的格式如:hh:mm:ss
setFormat("计时:%s"); //设置显示格式
setFormat(String format);//设置显示时间的格式。
start();//开始计时
stop();//停止计时
setBase();//设置基地时间,一般都是SystemClock.elapsedRealtime()
setOnChronometerTickListener(Chronometer.OnChronometerTickListener listener);//当计时器改变时调用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Chronometer
android:id="@+id/chronometer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/chronometer_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="开始计时"
/>
<Button
android:id="@+id/chronometer_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="停止计时"
/>
<Button
android:id="@+id/chronometer_null"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="重新开始计时"
/>
</LinearLayout>
package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
public class ChronometerDemo extends Activity {
private Chronometer chronometer;
private Button button_start, button_end,button_bull;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chronometer);
chronometer =(Chronometer)findViewById(R.id.chronometer);
button_start =(Button)findViewById(R.id.chronometer_start);
button_end =(Button)findViewById(R.id.chronometer_end);
button_bull =(Button)findViewById(R.id.chronometer_null);
button_start.setOnClickListener(clickListener);
button_end.setOnClickListener(clickListener);
button_bull.setOnClickListener(clickListener);
}
private OnClickListener clickListener = new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.chronometer_start:
//调用start()方法开始计时
chronometer.start();
button_start.setText("正在计时...");
break;
case R.id.chronometer_end:
//调用stop()方法停止计时
chronometer.stop();
button_start.setText("继续计时");
break;
case R.id.chronometer_null:
//调用stop()方法停止计时
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.start();
button_start.setText("正在计时...");
break;
default:
break;
}
}
};
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有