嘿伙计们,我想问一下我是否可以将虚拟计时器添加到我的进度框。
我希望我的进度框提示用户输入他的当前位置,然后输入他的目的地,所以当应用程序启动时,它会提示他输入他的用户名,在消息显示 2 秒后,消息将消失。我怎样才能实现他的
到目前为止的代码:
int timer = 0;
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Enter Current Location");
progressDialog.show();
// do { ++timer; } while ( timer != 500 ); // hiding after 500 iterations
progressDialog.hide();
do while 循环对我不起作用,还有其他选择吗?
最佳答案
它称为延迟,而不是虚拟计时器。
要添加延迟,请在 progressDialog.show()
函数之后添加此代码。
1500 毫秒延迟(1.5 秒);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
progressDialog.dismiss();
} }, 1500);
或 3000 毫秒延迟(3 秒);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
progressDialog.dismiss();
} }, 3000);
并在添加上述任一代码后从代码末尾删除 progressDialog.dismiss()
。
干杯。
关于android - ProgressDialog Box虚拟计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35585792/