我在这段代码中循环遍历对象的attaylist并为每个对象分配一个回调,但是当我开始使用CountDownTimer时,它崩溃了,因为无法在未调用Looper.prepare()的线程内创建处理程序
for ( final ABoxActor a : actList )
{
ActorDamageListener adl = new ActorDamageListener(){
public void ActorDestroyCallback() {
Log.e("KILLED", a.getBitmapName() );
}
public void ActorDamageCallback(float damage) {
Log.e("DAMAGED "+String.valueOf(damage), a.getBitmapName() );
a.setSpriteCurrentFrame(10);
//// THROWS Can't create handler inside thread that has not called Looper.prepare()
CountDownTimer t = new CountDownTimer(500,500){
@Override
public void onFinish() {
a.setSpriteCurrentFrame(15);
}
@Override
public void onTick(long millisUntilFinished) {
}}.start();
/////////////////////////////////
}
};
a.setListener(adl);
}
任何想法什么是解决这个问题的最简单方法?我可以以某种方式将此“循环器”添加到我的回调定义中吗?
谢谢!