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

Android控件Chronometer定時器的實現方法

 更新時間:2021年06月15日 14:23:20   作者:ForrestWoo  
這篇文章主要為大家詳細介紹了Android控件Chronometer定時器的實現方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Chronometer是一個簡單的定時器,你可以給它一個開始時間,并以此定時,或者如果你不給它一個開始時間,它將會使用你的時間通話開始。默認情況下它會顯示在當前定時器的值的形式“分:秒”或“H:MM:SS的”,或者可以使用的Set(字符串)格式的定時器值到一個任意字符串

1.重要屬性

android:format:定義時間的格式如:hh:mm:ss

2.重要方法

setBase(long base):設置倒計時定時器

setFormat(String format):設置顯示時間的格式。

start():開始計時

stop() :停止計時

setOnChronometerTickListener(Chronometer.OnChronometerTickListener listener):當計時器改變時調用。

3.實例

布局文件

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="4dip"
 android:gravity="center_horizontal"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <Chronometer android:id="@+id/chronometer"
 android:format="Initial format: "
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_weight="0"
 android:paddingBottom="30dip"
 android:paddingTop="30dip"
 />

 <Button android:id="@+id/start"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="開始">
 <requestFocus />
 </Button>

 <Button android:id="@+id/stop"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="停止">
 </Button>

 <Button android:id="@+id/reset"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="重置">
 </Button>

 <Button android:id="@+id/set_format"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="設置格式">
 </Button>

 <Button android:id="@+id/clear_format"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="清除格式">
 </Button>

</LinearLayout> 

主程序:

package wjq.WidgetDemo;

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 mChronometer;
 /* (non-Javadoc)
 * @see android.app.Activity#onCreate(android.os.Bundle)
 */
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 setContentView(R.layout.chronometerpage);
 Button button;

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

 // Watch for button clicks.
 button = (Button) findViewById(R.id.start);
 button.setOnClickListener(mStartListener);

 button = (Button) findViewById(R.id.stop);
 button.setOnClickListener(mStopListener);

 button = (Button) findViewById(R.id.reset);
 button.setOnClickListener(mResetListener);

 button = (Button) findViewById(R.id.set_format);
 button.setOnClickListener(mSetFormatListener);

 button = (Button) findViewById(R.id.clear_format);
 button.setOnClickListener(mClearFormatListener);
 }

 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);
 }
 };
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Android EventBus 3.0.0 使用總結(必看篇)

    Android EventBus 3.0.0 使用總結(必看篇)

    下面小編就為大家?guī)硪黄狝ndroid EventBus 3.0.0 使用總結(必看篇)。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • android 類似微信的搖一搖功能實現思路及代碼

    android 類似微信的搖一搖功能實現思路及代碼

    微信的搖一搖功能的出現,讓彼此之間的距離有近了一步,本文也想實現以下微信的搖一搖功能,感興趣的朋友可以了解下啊,希望本人對你有所幫助
    2013-01-01
  • Android全局獲取Context實例詳解

    Android全局獲取Context實例詳解

    這篇文章主要介紹了Android全局獲取Context實例詳解的相關資料,需要的朋友可以參考下
    2017-06-06
  • Android源碼學習之觀察者模式應用及優(yōu)點介紹

    Android源碼學習之觀察者模式應用及優(yōu)點介紹

    定義對象間一種一對多的依賴關系,使得當一個對象改變狀態(tài),則所有依賴于它的對象都會得到通知并被自動更新等等,需要了解的朋友可以參考下
    2013-01-01
  • 實現activity管理器一次退出所有activity

    實現activity管理器一次退出所有activity

    退出所有Activity網上有很多很多種說法,推薦的一種方法是自定義一個Activity管理器,來管理所有已打開的Activity,要退出的時候再通過這個管理器來退出所有Activity,下面是一個簡單的Activity管理器代碼
    2014-01-01
  • Android SwipeMenuListView框架詳解分析

    Android SwipeMenuListView框架詳解分析

    這篇文章主要介紹了Android SwipeMenuListView框架詳解分析的相關資料,需要的朋友可以參考下
    2016-10-10
  • Android之Gallery使用例子

    Android之Gallery使用例子

    本篇文章主要介紹了Android之Gallery使用例子,Gallery用來顯示圖片列表,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-01-01
  • Android自定義超級炫酷的ViewPage指示器

    Android自定義超級炫酷的ViewPage指示器

    由于應公司開發(fā)要求,有一個顏色漸變帶縮放的指示器,雖然網上很多大佬開源的指示器開源庫,但如果一直都是使用別人造的輪子,那么對于自身的能力是毫無提升作用的,即使是參考別人的,然后自己動手寫一遍那對于自身來說也是一種升華
    2022-07-07
  • Android Kotlin環(huán)境使用ButterKnife的方法

    Android Kotlin環(huán)境使用ButterKnife的方法

    本篇文章主要介紹了Android Kotlin環(huán)境使用ButterKnife的方法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • Android實現開機自動啟動Service或app的方法

    Android實現開機自動啟動Service或app的方法

    這篇文章主要介紹了Android實現開機自動啟動Service或app的方法,結合實例形式分析了Android開機自啟動程序的具體步驟與相關實現技巧,需要的朋友可以參考下
    2016-07-07

最新評論