最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android計(jì)時(shí)器chronometer使用實(shí)例講解

 更新時(shí)間:2016年04月20日 17:07:18   作者:chinahhucai  
這篇文章主要為大家詳細(xì)介紹了Android計(jì)時(shí)器chronometer使用實(shí)例,介紹了Android計(jì)時(shí)器chronometer基本使用方法,感興趣的小伙伴們可以參考一下

在Android中,可以使用計(jì)時(shí)器來實(shí)現(xiàn)對時(shí)間的監(jiān)測,這個(gè)類所實(shí)現(xiàn)的功能有開始計(jì)時(shí),停止計(jì)時(shí),重新計(jì)時(shí),設(shè)置計(jì)
時(shí)模式,下面列出計(jì)時(shí)器方法的原型:
long getBase();//返回基地的時(shí)間,由setBase(long)設(shè)置的
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ù)所對應(yīng)的值得,如果字符串的值
//為null,那么返回的值為MM:SS格式的
下面就來介紹一個(gè)實(shí)例:

package com.example.android.apis.view;

// Need the following import to get access to the app resources, since this
// class is in a sub-package.
import com.example.android.apis.R;

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 {
  Chronometer mChronometer;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.chronometer);

    Button button;

    mChronometer = (Chronometer) findViewById(R.id.chronometer);

    // Watch for button clicks.
    button = (Button) findViewById(R.id.start);
    button.setOnClickListener(mStartListener);//對應(yīng)的是開始計(jì)時(shí)

    button = (Button) findViewById(R.id.stop);
    button.setOnClickListener(mStopListener); //對應(yīng)的是停止計(jì)時(shí)

    button = (Button) findViewById(R.id.reset);
    button.setOnClickListener(mResetListener);//對應(yīng)的是重新置數(shù)

    button = (Button) findViewById(R.id.set_format);
    button.setOnClickListener(mSetFormatListener);//對應(yīng)的是設(shè)置時(shí)間的顯示格式

    button = (Button) findViewById(R.id.clear_format);
    button.setOnClickListener(mClearFormatListener);//對應(yīng)的是使用非格式的計(jì)時(shí)顯示功能
  }

  View.OnClickListener mStartListener = new OnClickListener() {
    public void onClick(View v) {
      mChronometer.start();
    }
  };

  View.OnClickListener mStopListener = new OnClickListener() {
    public void onClick(View v) {
      mChronometer.stop(); 
    }
  };

  View.OnClickListener mResetListener = new OnClickListener() {
    public void onClick(View v) {
      mChronometer.setBase(SystemClock.elapsedRealtime());
    }
  };

  View.OnClickListener mSetFormatListener = new OnClickListener() {
    public void onClick(View v) {
      mChronometer.setFormat("Formatted time (%s)");
    }
  };

  View.OnClickListener mClearFormatListener = new OnClickListener() {
    public void onClick(View v) {
      mChronometer.setFormat(null);
    }
  };
}

以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)使用Android計(jì)時(shí)器有所幫助,謝謝大家的閱讀。

相關(guān)文章

最新評論

枣庄市| 石狮市| 独山县| 衡水市| 道真| 申扎县| 永昌县| 潜山县| 田林县| 平利县| 布尔津县| 利辛县| 东乡县| 天气| 台南市| 乌恰县| 谷城县| 黑水县| 合阳县| 新疆| 肇东市| 泰州市| 丹寨县| 浦东新区| 江华| 泸州市| 和平县| 德庆县| 马公市| 灌阳县| 杂多县| 孟州市| 育儿| 临武县| 清原| 灯塔市| 松江区| 新兴县| 淮南市| 天门市| 齐齐哈尔市|