等待5秒钟 [英] Wait for 5 seconds

查看:80
本文介绍了等待5秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想等待5秒钟,然后再启动另一个公共无效方法.线程睡眠对我不起作用.如果有一种 wait()的方法不使用线程,我很想知道这一点.

I want to wait 5 seconds before starting another public void method. The thread sleep was not working for me. If there is a way of wait() without using Threads I would love to know that.

public void check(){
    //activity of changing background color of relative layout
}

我想等3秒钟,然后再更改相对的布局颜色.

I want to wait 3 seconds before changing the relative layout color.

推荐答案

只需添加带有lambda的单线即可

just add one-liner with lambda

(new Handler()).postDelayed(this::yourMethod, 5000);

为澄清起见: yourMethod 是指您要在5000毫秒后执行的方法.

edit for clarification: yourMethod refers to the method which you want to execute after 5000 milliseconds.

这篇关于等待5秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆