我在Android Java中获得了Handler的代码片段,它告诉我删除postDelayed参数周围的括号。
Handler handler = new Handler();
handler.postDelayed (runable, minute);
private Runnable runnable = new Runnable()
{
@Override
public void run()
{
biomass = biomass +1;
}
};
我希望程序在一分钟后将生物量增加1。 分钟已经在上面宣布为int minute = 60000;
我使用的代码片段是:www.mopri.de/2010/timertask-bad-do-it-the-android-way-use-a-handler /
答案 0 :(得分:1)
试试这个:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
biomass = biomass +1;
}
}, 6000);
答案 1 :(得分:0)
您可以使用Thread.sleep(6000)暂停Thread / Runnable,其中6000是毫秒数
private Runnable runnable = new Runnable()
{
@Override
public void run()
{
Thread.sleep(6000);
biomass = biomass +1;
}
};
new Thread(runnable).start();
答案 2 :(得分:0)
您在定义之前访问runnable.private无法在那里定义
Handler handler = new Handler();
final Runnable runnable = new Runnable()
{
@Override
public void run()
{
}
};
handler.postDelayed (runnable,c);