ProgressDialog 总是在 onClick 时关闭 - DoubleClick 不可能
ProgressDialog always closes on onClick - DoubleClick not possible
下面的 doubleClick
实现适用于我布局中的任何按钮。但是我不能让它与对话框按钮一起工作,onSingleClick
按预期工作但对话框立即被关闭。
即使 onClick
方法中没有任何内容,似乎也存在对 dialog.dismiss()
的隐藏调用....
dialog = new ProgressDialog(activity);
dialog.setMessage(activity.getString(R.string.msg_please_insert_card));
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DoubleClickDialogListener() {
@SuppressLint("ShowToast")
Toast mToast = Toast.makeText(activity, R.string.creditCard_tap_twice_cancel, Toast.LENGTH_SHORT);
@Override
public void onSingleClick() {
mToast.show();
}
@Override
public void onDoubleClick() {
mToast.cancel();
activity.finish(); // kill the Activity and go back to previous Activity
}
});
dialog.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
return true;
}
});
dialog.show();
public abstract class DoubleClickDialogListener implements DialogInterface.OnClickListener {
private static final long DOUBLE_CLICK_TIME_DELTA = 300;//milliseconds
long lastClickTime = 0;
@Override
public void onClick(DialogInterface dialog, int which) {
long clickTime = System.currentTimeMillis();
if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA){
onDoubleClick();
} else {
onSingleClick();
}
lastClickTime = clickTime;
}
public abstract void onSingleClick();
public abstract void onDoubleClick();
}
你是对的 - 单击按钮后总是关闭对话框。你对此无能为力。如果您需要更改此行为,则必须编写自己的对话框实现。
下面的 doubleClick
实现适用于我布局中的任何按钮。但是我不能让它与对话框按钮一起工作,onSingleClick
按预期工作但对话框立即被关闭。
即使 onClick
方法中没有任何内容,似乎也存在对 dialog.dismiss()
的隐藏调用....
dialog = new ProgressDialog(activity);
dialog.setMessage(activity.getString(R.string.msg_please_insert_card));
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DoubleClickDialogListener() {
@SuppressLint("ShowToast")
Toast mToast = Toast.makeText(activity, R.string.creditCard_tap_twice_cancel, Toast.LENGTH_SHORT);
@Override
public void onSingleClick() {
mToast.show();
}
@Override
public void onDoubleClick() {
mToast.cancel();
activity.finish(); // kill the Activity and go back to previous Activity
}
});
dialog.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
return true;
}
});
dialog.show();
public abstract class DoubleClickDialogListener implements DialogInterface.OnClickListener {
private static final long DOUBLE_CLICK_TIME_DELTA = 300;//milliseconds
long lastClickTime = 0;
@Override
public void onClick(DialogInterface dialog, int which) {
long clickTime = System.currentTimeMillis();
if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA){
onDoubleClick();
} else {
onSingleClick();
}
lastClickTime = clickTime;
}
public abstract void onSingleClick();
public abstract void onDoubleClick();
}
你是对的 - 单击按钮后总是关闭对话框。你对此无能为力。如果您需要更改此行为,则必须编写自己的对话框实现。