gpt4 book ai didi

android - 5000 毫秒后显示第二个警报对话框

转载 作者:行者123 更新时间:2023-11-29 16:22:51 25 4
gpt4 key购买 nike

这里我想在第一个对话框消失后显示第二个对话框。我正在显示第一个对话框 5000 毫秒,我们如何才能做到这一点?

提前致谢...!

 Button signin = (Button) findViewById(R.id.regsubmitbtn);

signin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog(0);
t = new Thread() {
public void run() {
register();
try {
Thread.sleep(5000);
removeDialog(0);

e.printStackTrace();
}
}
};
t.start();
}
});
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0: {
dialog = new ProgressDialog(this);
dialog.setMessage("Registering...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
return dialog;
}
}
return null;
}

最佳答案

创建一个计数器来计算对话框的创建次数,然后创建一个处理程序,您将通过该处理程序发送消息是显示对话框还是关闭。

请看下面的代码。它完全符合您的要求

例子

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main extends Activity{

Button btn = null;
ProgressDialog dialog = null;
int counter = 0;
Thread t =null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.myxml);

btn = (Button) findViewById(R.id.btn001);
btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// tv.setHint(tv.getHint());
// while(counter<2){

t = new Thread() {
public void run() {
// register();
try {
while(counter<2){
updateGallery(0);
Thread.sleep(5000);

updateGallery(1);
Thread.sleep(1000);

}

}catch(Exception ex){
ex.printStackTrace();
}
}
};
t.start();

}
// tv.setTextColor(getResources().getColor(R.color.DarkBlue));
// }
});



// tv.setFreezesText(true);
}




@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0: {

++counter;
dialog = new ProgressDialog(this);
if(counter==1){
dialog.setMessage("Registering...");
}else{
dialog.setMessage("Registered successfully");
}
dialog.setIndeterminate(true);
dialog.setCancelable(true);

}

}
return dialog;
}

public void updateGallery(int actionsToBePerformedOnScreen) {
Message msg = new Message();
msg.what = actionsToBePerformedOnScreen;
galleryListHandler.sendMessage(msg);

}

public Handler galleryListHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:

showDialog(0);

break;

case 1:
// clear all images in the list
removeDialog(0);
break;


}

};
};
}

关于android - 5000 毫秒后显示第二个警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6463854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com