Android 時間倒計時

2021-08-16 15:29:25 字數 1302 閱讀 7614

android時間倒計時在網上一搜就一堆,而且也經常用到。備份一下,以便下次直接使用

1、首先我建立乙個介面,為什麼要建立乙個介面呢?因為我是建立了乙個類繼承countdowntimer。這樣做的意義就是不用每次

需要用到的倒計時的時候不需要在activity裡面建立直接呼叫就可以了。

public inte***ce oncountdowntimelistener until the countdown is done and

*                          is called.

* @param countdowninterval the interval along the way to receive

*                           callbacks.

*/private oncountdowntimelistener listener;

handler mhandler = new handler()}};

public countdownthread(long millisinfuture, long countdowninterval)

public void setoncountdowntimelistener(oncountdowntimelistener listener)

@override

public void ontick(long millisuntilfinished)

@override

public void onfinish()

}3、在activity的呼叫,其中使用了butterknife

public class countdownactivity extends activity implements oncountdowntimelistener

//開始時間倒計時

private void startcountdowntime(int time)

countdownthread = new countdownthread(time * 1000, 1000);

countdownthread.setoncountdowntimelistener(this);

countdownthread.start();

}@override

public void getcountdowntime(int time)

@override

public void timeover()

4、相應的布局

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

時間倒計時

一 技術要點 做乙個 分鐘 秒 根據不同的初始時間倒計時到 00 00 的效果 1 取得雙標籤元素的內容如取這是我的 中的 這是我的 2 根據特定字元分割字串例如 35 28 根據 把字串分為兩部分35與28 3 把帶有數字的string型別轉變為int型別的資料 4 多個if else巢狀的使用 ...

時間倒計時

關於倒計時時間的計算 當前的時間 一小時之後的時間 時間差 而當前的時間一直地在增加,那麼時間差也就會縮小 從而達到倒計時的效果 關於時間格式的計算 var now new date gettime var end new date 2016 7 26 22 40 gettime 因為1000毫秒是...

Android倒計時控制項

專案有乙個倒計時特賣的需求 具體 如下 import android.content.context import android.util.attributeset import android.widget.textview public class timertextview extends ...