我正在尝试使用多个倒数计时器在主要活动上打勾。计时器将具有一个对象字符串,将在列表视图中显示。问题是计时器没有滴答,它保持静止。
这是我的主要活动部分
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;
}
答案 0 :(得分:0)
是否可以执行以下runnable(在您的给定代码中)?
Runnable r = new Runnable() {
@Override
public void run() {
BountyList.get(0).getTime().start();
ListAdapter.notifyDataSetChanged();
}
};
答案 1 :(得分:0)
countdowntimer必须在一个活动类中执行才能运行。这可以通过扩展类似的类来完成,
public class timeractivity extends Activity{
//run timer here
}