0
我正在嘗試使多個倒計時器在主要活動上打勾。定時器將有一個對象字符串,如列表視圖中所示。問題是計時器沒有滴答下來,它保持靜態。列表視圖中的多個倒計時器
這是我的主要活動
final ListView list = (ListView) findViewById(R.id.listView2);
final ArrayAdapter ListAdapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,BountyList);
list.setAdapter(ListAdapter);
Runnable r = new Runnable() {
@Override
public void run() {
BountyList.get(0).getTime().start();
ListAdapter.notifyDataSetChanged();
}
};
r.run();
這裏是處理我的字符串,並保持我的定時器對象的對象類的部分。
public class Bounty {
String BountyName;
String URL;
String timelapse;
int BountyAmount;
long exHour, exMin, exSec;
CountDownTimer time;
//ArrayAdapter a;
public Bounty(String name, String url,int Amount,long hour, long min, long sec){//maybe add Adapter as local to handle it here?
BountyName = name;
BountyAmount = Amount;
exHour = hour *60*60*1000;
exMin = min *60* 1000;
exSec = sec *1000;
URL = url;
final long test = (exHour+exMin+exSec) ;
//a = adapter;
//adapter.notifyDataSetChanged();
time = new CountDownTimer(test,1000) {
@Override
public void onTick(long millisUntilFinished) {
//long test2 = -1;
//if(test2 == -1){
// test2 = test;
//}
//test2 = test2 - 1000;
timelapse = toHourFormat(millisUntilFinished);
}
@Override
public void onFinish() {
}
}.start();// not ticking so wont show toString
}
public String toString(){
if(timelapse==null){
timelapse = "Issue Here";
}
return BountyName+" | "+ BountyAmount+" | " + timelapse;
}
public String toHourFormat(long milli){
int second = (int) (milli/1000) % 60 ;
int minutes = (int) ((milli/(1000*60)) % 60);
int hours = (int) ((milli/(1000*60*60)) % 24);
return hours+":"+minutes+":"+second;
}
public CountDownTimer getTime(){
return time;
}
我應該看到一個新的線程是否有幫助 – Ossusum
@Ossusum你叫'.RUN()'這個'Runnable'? – Simas
是的,我還是不會打勾 – Ossusum