ProgressDialog始终在onClick上关闭 - DoubleClick无法实现

时间:2015-06-30 10:08:34

标签: android progressdialog

下面的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();
}

1 个答案:

答案 0 :(得分:1)

你是对的 - 单击按钮后对话框总是被取消。你无能为力。如果您需要更改此行为,则必须编写自己的对话框实现。