日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android listview countdowntimer,Android-ListView中的CountDownTimer随机闪烁

發布時間:2024/9/27 Android 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android listview countdowntimer,Android-ListView中的CountDownTimer随机闪烁 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在使用計時器制作列表視圖,每個計時器都有不同的截止日期,具體取決于數據庫(類似于拍賣)

Time now = new Time();

now.setToNow();

now.normalize(true);

nowMillis = now.toMillis(true);

.

.

String endtime = a.get(position).get(TAG_ENDTIME);

Integer timeSecond = Integer.parseInt(endtime.substring(17, 19));

Integer timeMinute = Integer.parseInt(endtime.substring(14, 16));

Integer timeHour = Integer.parseInt(endtime.substring(11, 13));

Integer timeDay = Integer.parseInt(endtime.substring(0, 2));

Integer timeMonth = Integer.parseInt(endtime.substring(3, 5)) - 1;

Integer timeYear = Integer.parseInt(endtime.substring(6, 10));

Time future = new Time();

future.set(timeSecond, timeMinute, timeHour, timeDay, timeMonth, timeYear);

future.normalize(true);

long futureMillis = future.toMillis(true);

long interval = futureMillis - nowMillis;

new CountDownTimer(interval,1000)

{

@Override

public void onTick(long millisUntilFinished)

{

Long interval = millisUntilFinished;

int days = (int) ((millisUntilFinished / 1000) / 86400);

int hours = (int) (((millisUntilFinished / 1000) - (days * 86400)) / 3600);

int minutes = (int) (((millisUntilFinished / 1000) - (days * 86400) - (hours * 3600)) / 60);

int seconds = (int) ((millisUntilFinished / 1000) % 60);

String countdown = String.format("%dd %dh %dm %ds", days, hours, minutes, seconds);

holder.duration.setText(countdown);

}

@Override

public void onFinish()

{

// TODO Auto-generated method stub

holder.duration.setText(TimeUp);

}

}.start();

當只有一個實例時,該代碼幾乎可以完美工作。

但是,當有多個實例同時運行大約4-5個計時器時,就會出現問題

幾秒/全部倒計時將開始閃爍,無論是秒,分鐘,小時還是天。

例如我的計時器在27d 11h 54m 50s和0d 23h 47m 0s之間閃爍

由于這種情況在模擬器和設備上均會發生,這似乎是我的代碼的缺陷,但是我不知道是什么原因引起的。

我試圖改變

holder.duration.setText(countdown) 進入

holder.duration.setText(millisUntilFinished)

并且倒計時會在所需的持續時間和巨大的隨機數之間閃爍,

請幫忙。

總結

以上是生活随笔為你收集整理的android listview countdowntimer,Android-ListView中的CountDownTimer随机闪烁的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。