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

Android計(jì)時(shí)器控件Chronometer應(yīng)用實(shí)例

 更新時(shí)間:2017年09月28日 16:32:47   作者:極客Dragon  
這篇文章主要為大家詳細(xì)介紹了Android計(jì)時(shí)器控件Chronometer應(yīng)用實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

顯示一個(gè)計(jì)時(shí)器開(kāi)始計(jì)時(shí),當(dāng)計(jì)時(shí)器到達(dá)15s的時(shí)候,停止計(jì)時(shí)。此時(shí)頁(yè)面多一個(gè)重置按鈕,可再次進(jìn)行計(jì)時(shí)。


頁(yè)面布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:id="@+id/LinearLayout1" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:orientation="horizontal" 
 android:paddingBottom="@dimen/activity_vertical_margin" 
 android:paddingLeft="@dimen/activity_horizontal_margin" 
 android:paddingRight="@dimen/activity_horizontal_margin" 
 android:paddingTop="@dimen/activity_vertical_margin" 
 tools:context=".MainActivity" 
 android:background="@drawable/bg" > 
 
 <Chronometer 
  android:id="@+id/chronometer" 
  android:layout_marginTop="8dp" 
  android:layout_marginLeft="5dp" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" /> 
 
 <Button 
  android:id="@+id/restart" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:text="重置" 
  android:visibility="gone" /> 
 
</LinearLayout> 

事件響應(yīng) 

package com.example.chronometerdemo; 
 
import android.os.Bundle; 
import android.os.SystemClock; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Chronometer; 
import android.widget.Chronometer.OnChronometerTickListener; 
 
public class MainActivity extends Activity 
{ 
 Chronometer time=null; 
 Button restart=null; 
 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_main); 
   
  time=(Chronometer) findViewById(R.id.chronometer); 
  restart=(Button) findViewById(R.id.restart); 
   
  //設(shè)置起始時(shí)間和時(shí)間格式,然后開(kāi)始計(jì)時(shí) 
  time.setBase(SystemClock.elapsedRealtime()); 
  time.setFormat("已用時(shí)間:%s"); 
  time.start(); 
   
  //給計(jì)時(shí)器添加監(jiān)聽(tīng)器,當(dāng)計(jì)時(shí)到達(dá)15s時(shí),要重置 
  time.setOnChronometerTickListener(new OnChronometerTickListener() { 
    
   @Override 
   public void onChronometerTick(Chronometer arg0) 
   { 
    if(SystemClock.elapsedRealtime()-arg0.getBase()>=15000) 
    { 
     arg0.stop(); 
     restart.setVisibility(View.VISIBLE); 
    } 
     
   } 
  }); 
   
  //給按鈕添加重置的效果 
  restart.setOnClickListener(new OnClickListener() { 
    
   @Override 
   public void onClick(View arg0) 
   { 
    time.setBase(SystemClock.elapsedRealtime()); 
    time.start(); 
    restart.setVisibility(View.GONE); 
     
   } 
  }); 
 } 
 
 
 @Override 
 public boolean onCreateOptionsMenu(Menu menu) { 
  // Inflate the menu; this adds items to the action bar if it is present. 
  getMenuInflater().inflate(R.menu.main, menu); 
  return true; 
 } 
  
} 

運(yùn)行效果


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

相關(guān)文章

  • android實(shí)現(xiàn)雙日期選擇控件(可隱藏日,只顯示年月)

    android實(shí)現(xiàn)雙日期選擇控件(可隱藏日,只顯示年月)

    本篇文章主要介紹了android實(shí)現(xiàn)雙日期選擇控件(可隱藏日,只顯示年月) ,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。
    2017-01-01
  • 詳解關(guān)于AndroidQ獲取不到imsi解決方案

    詳解關(guān)于AndroidQ獲取不到imsi解決方案

    這篇文章主要介紹了詳解關(guān)于AndroidQ獲取不到imsi解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • 談?wù)凙ndroid Fragments 詳細(xì)使用

    談?wù)凙ndroid Fragments 詳細(xì)使用

    本篇文章主要介紹了Android Fragments 詳細(xì)使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-12-12
  • Android自定義view之圍棋動(dòng)畫(huà)效果的實(shí)現(xiàn)

    Android自定義view之圍棋動(dòng)畫(huà)效果的實(shí)現(xiàn)

    這篇文章主要介紹了Android自定義view之圍棋動(dòng)畫(huà)效果的實(shí)現(xiàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • Android圖像處理之霓虹濾鏡效果

    Android圖像處理之霓虹濾鏡效果

    這篇文章主要介紹了Android圖像處理之霓虹濾鏡效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android SpringAnimation彈性動(dòng)畫(huà)解析

    Android SpringAnimation彈性動(dòng)畫(huà)解析

    這篇文章主要為大家詳細(xì)介紹了Android SpringAnimation彈性動(dòng)畫(huà),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Convert WebP to PNG using java

    Convert WebP to PNG using java

    本文主要介紹Convert WebP to PNG using java,這里對(duì) WebP 做了詳細(xì)說(shuō)明,并講解Linux 環(huán)境下WebP 轉(zhuǎn)png格式的示例,有興趣的小伙伴可以參考下
    2016-08-08
  • android使用AIDL跨進(jìn)程通信(IPC)

    android使用AIDL跨進(jìn)程通信(IPC)

    本篇文章主要介紹了 android跨進(jìn)程通信(IPC):使用AIDL,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • Android自定義listview布局實(shí)現(xiàn)上拉加載下拉刷新功能

    Android自定義listview布局實(shí)現(xiàn)上拉加載下拉刷新功能

    這篇文章主要介紹了Android自定義listview布局實(shí)現(xiàn)上拉加載下拉刷新功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-12-12
  • Python基礎(chǔ)教程學(xué)習(xí)筆記 第二章 列表和元組

    Python基礎(chǔ)教程學(xué)習(xí)筆記 第二章 列表和元組

    這篇文章主要介紹了Python基礎(chǔ)教程學(xué)習(xí)筆記 第二章 列表和元組,需要的朋友可以參考下
    2015-03-03

最新評(píng)論

威海市| 桐庐县| 蕉岭县| 交城县| 常宁市| 铜梁县| 雷山县| 东乌珠穆沁旗| 中方县| 上蔡县| 高淳县| 杭锦旗| 花莲市| 古蔺县| 噶尔县| 钟祥市| 土默特左旗| 资源县| 资中县| 巨鹿县| 通山县| 石嘴山市| 湟中县| 平邑县| 镇雄县| 旅游| 始兴县| 山西省| 兴业县| 徐水县| 玉林市| 东乡县| 蒲江县| 杂多县| 湾仔区| 元氏县| 锡林浩特市| 江陵县| 开鲁县| 深水埗区| 二手房|