android - 我如何在 android studio 中编写:如果条件至少在 5 秒内为真,那么做点什么?
问题描述
以下是我当前的代码。然而问题是图像不断闪烁。
CountDownTimer mCountDownTimer = new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished){}
public void onFinish() {
image1.setVisibility(View.VISIBLE);
}
};
if (dan > -1) {
mCountDownTimer.start();
} else {
image1.setVisibility(View.GONE);
mCountDownTimer.cancel();
}
解决方案
var isFalseAfterDelay = false
if (!isFalseAfterDelay) {
isFalseAfterDelay = true//this will be true till 5 sec then it will false
Handler().postDelayed( {
isFalseAfterDelay = false
},5000)// this will delay your operation for 5 sec
}
推荐阅读
- java - 无法通过java代码触发jenkins作业
- c# - C# Httpwebrequest 手动重定向
- php - Laravel 使用原始字符串创建表
- appium - 使用 Appium 的 getDeviceName 和 getVersion 运行时
- python - DataFrame中的GroupBy值并获取以逗号分隔的单词列表
- cron - Cronjob- 每周一每小时
- javascript - 用正则表达式替换字符串会覆盖不匹配的字符
- python - 在循环中列出比较:如果条件打印第二个元组元素
- c# - Bootstrap Modal 不适用于 asp.net
- javascript - 如果在车把条件下无法使用