我试着寻找答案,发现了一些但对我不起作用.我想在开始另一个公共void方法之前等待5秒钟.线程睡眠不适合我.请提出你的建议,如果有一种"wait()"方式而不使用Threads我很想知道.
public void check(){
//activity of changing background color of relative layout
}
Run Code Online (Sandbox Code Playgroud)
我想在更改相对布局颜色之前等待3秒钟.
see*_*ess 55
看看这是否适合你.一定要导入android.os.Handler
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// yourMethod();
}
}, 5000); //5 seconds
Run Code Online (Sandbox Code Playgroud)
小智 22
只需添加带有lambda的单线程
(new Handler()).postDelayed(this::yourMethod, 5000);
Run Code Online (Sandbox Code Playgroud)
小智 8
你可以使用java处理程序来完成你的任务:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// Actions to do after 5 seconds
}
}, 5000);
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请阅读以下网址:
https://developer.android.com/reference/android/os/Handler.html
小智 6
进口用途:import android.os.Handler;
new Handler().postDelayed(new Runnable() {
public void run() {
// yourMethod();
}
}, 5000); // 5 seconds
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53752 次 |
| 最近记录: |