欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)戰(zhàn)教程第四十篇之Chronometer實(shí)現(xiàn)倒計(jì)時(shí)

 更新時(shí)間:2016年11月10日 10:57:08   作者:楊道龍  
這篇文章主要介紹了Android實(shí)戰(zhàn)教程第四十篇之Chronometer實(shí)現(xiàn)倒計(jì)時(shí),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Android提供了實(shí)現(xiàn)按照秒計(jì)時(shí)的API,今天就是用這個(gè)API實(shí)現(xiàn)簡單的倒計(jì)時(shí)。

來個(gè)布局:

<?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/myChronometer" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" /> 
 
 <LinearLayout 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:orientation="horizontal" > 
 
 <Button 
  android:id="@+id/btnStart" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:text="開始計(jì)時(shí)" /> 
 
 <Button 
  android:id="@+id/btnStop" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:text="停止" /> 
 
 <Button 
  android:id="@+id/btnBase" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:text="復(fù)位" /> 
 
 <Button 
  android:id="@+id/btnFormat" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:text="格式化" /> 
 </LinearLayout> 
 
</LinearLayout> 

對(duì)應(yīng)活動(dòng)中的代碼如下:

package com.example.timer; 
 
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 MainActivity extends Activity { 
 private Chronometer myChronometer = null; 
 private Button btnStart = null; 
 private Button btnStop = null; 
 private Button btnBase = null; 
 private Button btnFormat = null; 
 
 public void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); // 生命周期方法 
 super.setContentView(R.layout.activity_main); // 設(shè)置要使用的布局管理器 
 this.myChronometer = (Chronometer) super 
  .findViewById(R.id.myChronometer); 
 btnStart = (Button) super.findViewById(R.id.btnStart); 
 btnStop = (Button) super.findViewById(R.id.btnStop); 
 btnBase = (Button) super.findViewById(R.id.btnBase); 
 btnFormat = (Button) super.findViewById(R.id.btnFormat); 
 btnStart.setOnClickListener(new OnClickListenerStart()); 
 btnStop.setOnClickListener(new OnClickListenerStop()); 
 btnBase.setOnClickListener(new OnClickListenerBase()); 
 btnFormat.setOnClickListener(new OnClickListenerFormat()); 
 } 
 
 private class OnClickListenerStart implements OnClickListener { 
 
 public void onClick(View arg0) { 
  myChronometer.start(); 
 
 } 
 
 } 
 
 private class OnClickListenerStop implements OnClickListener { 
 
 public void onClick(View arg0) { 
  myChronometer.stop(); 
 
 } 
 
 } 
 
 private class OnClickListenerBase implements OnClickListener { 
 
 public void onClick(View arg0) { 
  myChronometer.setBase(SystemClock.elapsedRealtime()); 
 
 } 
 
 } 
 
 private class OnClickListenerFormat implements OnClickListener { 
 
 public void onClick(View arg0) { 
  myChronometer.setFormat("新的顯示格式:%s。"); 
 
 } 
 
 } 
 
} 

運(yùn)行跑起來看看效果:

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

相關(guān)文章

最新評(píng)論