亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android自帶倒計(jì)時(shí)控件Chronometer使用方法詳解

 更新時(shí)間:2016年11月10日 11:28:52   作者:Android_小新哥哥  
這篇文章主要為大家詳細(xì)介紹了Android自帶倒計(jì)時(shí)控件Chronometer的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

公司的以前的項(xiàng)目,看到使用了這個(gè)Android自帶的倒計(jì)時(shí)控件Chronometer,現(xiàn)在整合了一下

先看看效果:

<Chronometer 
 android:id="@+id/chronometer" 
 android:layout_width="wrap_content" 
 android:layout_height="30dp" /> 
 <Button 
 android:onClick="start" 
 android:text="開始" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" /> 
 <Button 
 android:onClick="stop" 
 android:text="停止" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" /> 
 <Button 
 android:onClick="reset" 
 android:text="重置" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" /> 

方法簡(jiǎn)介:

long getBase(); //返回基地的時(shí)間,由setBase(long)設(shè)置的,可以是SystemClock.elapsedRealtime() 
String getFormat();//返回當(dāng)前字符串格式,此格式是通過setFormat()實(shí)現(xiàn)的
void setBase(long base);//設(shè)置時(shí)間,計(jì)數(shù)定時(shí)器指定的值
void setFormat(String format);//設(shè)置顯示的內(nèi)容,計(jì)時(shí)器將會(huì)顯示這個(gè)參數(shù)所對(duì)應(yīng)的值得,如果字符串的值為null,那么返回的值為MM:SS格式的
private Chronometer chronometer; 
 private long recordTime;//記錄下來的總時(shí)間 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_main); 
 chronometer= (Chronometer) findViewById(R.id.chronometer); 
 chronometer.setFormat("計(jì)時(shí):%s");//設(shè)置顯示的格式 
 Toast.makeText(MainActivity.this, ""+recordTime, Toast.LENGTH_SHORT).show(); 
 } 
 public void start(View view){ 
 chronometer.setBase(SystemClock.elapsedRealtime()-recordTime);//跳過已經(jīng)記錄的時(shí)間 
 chronometer.start(); 
 } 
 public void stop(View view){ 
 chronometer.stop(); 
 recordTime=SystemClock.elapsedRealtime()-chronometer.getBase();//保存這次記錄的時(shí)間 
 } 
 public void reset(View view){ 
 recordTime=0;//重置時(shí)間 
 chronometer.setBase(SystemClock.elapsedRealtime()); 
 } 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論