Wyy.java

package com.test;

import android.app.Activity;
import android.app.Service;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.AutoCompleteTextView.Validator;
import android.widget.Chronometer.OnChronometerTickListener;

public class Wyy extends Activity{

private Chronometer ch1 = null;
private Button chStart = null;
private Button chStop = null;
private Vibrator vibrator = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.wyy);
this.ch1 = (Chronometer) super.findViewById(R.id.ch1);
this.vibrator = (Vibrator) super.getApplication().getSystemService(Service.VIBRATOR_SERVICE);
this.chStart = (Button) super.findViewById(R.id.chStart);
this.chStop = (Button) super.findViewById(R.id.chStop);
ch1.setOnChronometerTickListener(new OnChronometerTickListener() {
public void onChronometerTick(Chronometer chronometer) {
// TODO Auto-generated method stub
String time = chronometer.getText().toString().replaceAll("[^(\\d{2}:\\d{2})]", "");
if("00:01".equals(time)){
vibrator.vibrate(new long[]{1000,1000,2000,3000},0);
}
}
});
this.chStop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ch1.stop();
}
});
this.chStart.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ch1.start();
}
});
this.ch1.setFormat("当前计时时间:%s。");
//this.ch1.setOnChronometerTickListener(new OnChronometerTickListenerImpl() );

}
}

wyy.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<Chronometer
android:id="@+id/ch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="horizontal"
>
<Button
android:text="开始计时"
android:id="@+id/chStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<Button
android:text="停止计时"
android:id="@+id/chStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>

Android计时器实现的更多相关文章

  1. Android计时器TimerTask,Timer,Handler

    Android计时器TimerTask,Timer,若要在TimerTask中更新主线程UI,鉴于Android编程模型不允许在非主线程中更新主线程UI,因此需要结合Android的Handler实现 ...

  2. Chronometer控件实现的Android计时器

    本文为大家演示了如何使用Chronometer控件实现Android计时器的实例. 先贴上最终的实现效果图: Android计时器实现思路 使用Chronometer控件实现计器的操作.通过设置set ...

  3. Android计时器和倒计时

    Android计时器和倒计时 计时器两个核心类 Timer 和 TimerTask 1) Timer核心方法 Java代码  //Schedules the specified task for ex ...

  4. Android计时器实例

    布局文件 <Chronometer android:id="@+id/chronometer" android:layout_width="wrap_content ...

  5. Android计时器 android.widget.Chronometer

    说起做定时器,大家一般会想到Timer和Executors的定时器线程池,其实用这两个做都会有问题,在停止和重新计时时你回发现无法停止或者说计时加快(加快是因为多个线程在记录同一个变量),Androi ...

  6. android 计时器

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  7. android 计时器,倒计时

    自己定义CountDownTimer /** * 计时器 * @author Administrator * */ class TimeCount extends CountDownTimer{ pu ...

  8. Android计时器Chronometer-android学习之旅(二十一)

    Chronometer简介 Chronometer和DigitalColok都继承与TextView,但是Chronometer不是显示的当前时间,而是从某个时间开始又过去了多少时间,是一个时间差. ...

  9. Android NumberProgressBar:动态移动显示百分比进度的进度条

     Android NumberProgressBar:动态移动显示百分比进度的进度条 NumberProgressBar是github上一个开源项目,其项目主页是:https://github.c ...

随机推荐

  1. python3和python2的区别部分

    字典没有iteritems(),只有items() py2items()返回的是列表,iteritems()返回的是迭代器 py3items()返回的是迭代器

  2. seajs加载jquery提示$ is not a function

    jquery1.7以上的都支持模块化加载,只是jquery默认的是支持amd,不支持cmd.所以要用seajs加载jquery,需要稍微改下jquery 把 if (typeof define === ...

  3. 在国内使用maven下载jar包非常慢的解决方法

    在国内使用maven下载jar包非常慢的解决方法 1.原因: 很多jar包在国外环境,所以会很慢. 2.解决方法 maven支持镜像环境下载,所以首先找到maven的conf目录中的settings. ...

  4. 【算法系列学习】Dijkstra单源最短路 [kuangbin带你飞]专题四 最短路练习 A - Til the Cows Come Home

    https://vjudge.net/contest/66569#problem/A http://blog.csdn.net/wangjian8006/article/details/7871889 ...

  5. 自定义list排序

    使用扩展方法OrderBy,OrderByDescending,效果优良. 实现代码如下: private static void SortByExtensionMethod() { List< ...

  6. 573. Squirrel Simulation

    Problem statement: There's a tree, a squirrel, and several nuts. Positions are represented by the ce ...

  7. 568. Maximum Vacation Days

    Problem statement:  LeetCode wants to give one of its best employees the option to travel among N ci ...

  8. stl string常用函数

    string类的构造函数: string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 此外,string类还支持默认构造 ...

  9. 初识Celery

    本系列文章的开发环境: window + python2. + pycharm5 + celery3.1.25 + django1.9.4 在我们日常的开发工作中,经常会遇到这几种情况: 1.在web ...

  10. 单页应用跳转ui-view,$stateProvider,$urlRouterProvider

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta charset="UTF- ...