下面的代码应该显示一个对话框,然后根据程序的状态,在doseDownCourt()
单击 OK 关闭对话框时执行一些动画(通过调用来执行)。
问题是对话框在关闭时不会立即消失——它停留在屏幕上,“确定”按钮处于“按下”状态(蓝色阴影),而动画正在执行和显示。对话框会一直停留在屏幕上,直到动画完成。
我尝试更改命令执行的顺序,还尝试使用线程使动画在开始之前等待对话框消失,但无法获得我想要的行为。
任何建议,将不胜感激。谢谢。
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
String message;
Drawable puffle;
Drawable dr;
if (made == true) {
message = "You made it!!!";
dr = getResources().getDrawable(R.drawable.puff_happy);
}
else {
message = "Aw, you missed. Better luck after your next dose!";
dr = getResources().getDrawable(R.drawable.puff_confused);
}
builder.setMessage(message);
Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
puffle = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 200, 200, true));
builder.setTitle(" ");
builder.setIcon(puffle);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alertDialog.dismiss();
drawAll(); //put ball and shadow back with avatar
doseDownCourt(); //call doseDownCourt in case multiple doses have been taken before a shot for each has been attempted
}
});
alertDialog = builder.create();
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams WMLP = alertDialog.getWindow().getAttributes();
WMLP.y = -300; //y position of dialog box
alertDialog.getWindow().setAttributes(WMLP);
alertDialog.show();