我有一个关于按顺序显示警报对话框的问题。我正在尝试显示三个警报对话框,但每次第三个是第一个出现的第一个,在这种情况下第二个应该是第二个,第一个总是最后一个。我希望它们按代码顺序显示。请考虑代码并建议我为什么会发生这种情况以及一个可靠的解决方案。
私有静态类 MyHandler 扩展 Handler {
MainActivity activity;
public MyHandler(MainActivity activity){
this.activity = activity;
}
@Override
public void handleMessage(Message msg)
{
if(activity.connectionToTupleSpace == true)
{
activity.showDialog("Dialog 1", "It should be displayed first");
activity.showDialog("Dialog 2", "It should be displayed second");
activity.showDialog("Dialog 3", "It should be displayed third");
}
else
{
Toast.makeText(activity.getBaseContext(), " No connection to Tuple Space Server", Toast.LENGTH_SHORT).show();
}
}
};//handler for Thread
private void showDialog(String title, String message)
{
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton("OK", null);
builder.show();
}