java - 如何在用户按下 imageButton 之间添加延迟?
问题描述
我想让它让用户在允许按下 imageButton 之前等待很短的时间,我不知道最好的方法。
private class HandleClick implements View.OnClickListener {
public void onClick(View arg0) {
if(arg0.getId()==R.id.imageButton){
((TextView) findViewById(R.id.textView2)).setText("Pressed: " + ++howManyClicks1);
/* Uri uri = Uri.parse("https://abr.se/happyeno/?get=happyeno_svar_put&svar_id=1");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);*/
simpleWebView.loadUrl("https://abr.se/happyeno/?get=happyeno_svar_put&svar_id=1");
//startActivity(intent);
}
else if (arg0.getId()==R.id.imageButton1){
((TextView) findViewById(R.id.textView3)).setText("Pressed: " + ++howManyClicks2);
/*Uri uri = Uri.parse("https://abr.se/happyeno/?get=happyeno_svar_put&svar_id=2");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//startActivity(intent);*/
simpleWebView.loadUrl("https://abr.se/happyeno/?get=happyeno_svar_put&svar_id=2");
}
else if (arg0.getId()==R.id.imageButton2){
((TextView) findViewById(R.id.textView5)).setText("Pressed: " + ++howManyClicks3);
/*Uri uri = Uri.parse("https://abr.se/happyeno/?get=happyeno_svar_put&svar_id=3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//startActivity(intent);*/
simpleWebView.loadUrl("https://abr.se/happyeno/?get=happyeno_svar_put&svar_id=3");
}
}
}
我不希望用户能够点击 imageButtons 进行垃圾邮件。也许最好的方法是在按下按钮后添加延迟或在短时间内禁用按钮?
解决方案
在您的点击监听器中尝试倒数计时器
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
//count down 5,4,3,2,1.
}
public void onFinish() {
//Write you logic here
}
}.start();
推荐阅读
- swift - MKPointAnnotation 到 MKMapItem
- python - 无法在pygame中在全屏和窗口模式之间切换
- ios - iOS Swift Coordinator 模式和导航控制器的后退按钮
- mysql - 带条件的内部连接 - Mysql
- javascript - 隐藏时按id获取元素并显示:无
- django - 在 Django 的消息框架中添加不带文本的消息
- mysql - Mysql求和列值并用总计更新其他字段
- javascript - 在原型与构造函数中声明属性?优点和缺点?
- python - Shebang 在脚本中使用 virtualenv 解释器和 Apache 中的 Web 脚本
- c# - 使用 UseInMemoryDatabase 的 Entity Framework Core 迁移错误