即使没有单击按钮且setcancelable为false,AlertDialog.Builder也会消失

时间:2017-05-21 15:11:46

标签: android alertdialog

所以我使用一个警告对话框,它甚至不会持续5秒钟而不会立即消失,虽然我不会点击任何人可以帮助吗?

{{1}}

deletecopy()删除数据库中与当前创建的一行具有相同名称的任何行...任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

我不知道这是否有效,但就像我在评论中说的那样,你必须将你的点击后逻辑移动到onClickListener

private void setAlarm(Calendar targetCal) {
    deleteCopyAsk(targetCal);
}

public void deleteCopyAsk(final Calendar targetCal) {
    Cursor cursor = dba.getnameofAlarm(title.getText().toString());
    if (cursor.moveToFirst()) {
        final DatabaseActivity dba = new DatabaseActivity(getApplicationContext());
        String titleData = (cursor.getString(cursor.getColumnIndex(Constants.COLUMN_NAME)));
        if (title.getText().toString().matches(titleData)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(TimeDateRem.this);
            builder.setTitle("Set Alarm");
            builder.setMessage("By setting this alarm you will be deleting the previous one, is that OK?")
                    .setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            dba.deleteAlarm(title.getText().toString().trim());

                            info.setText("\n\n***\n"
                                    + "Alarm is set @ " + targetCal.getTime() + "\n"
                                    + "***\n");

                            Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
                            pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
                            alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                            alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
                            Intent alarmIIntent = new Intent(this, AlarmReceiver.class);
                            Intent intent_ForResult = new Intent(TimeDateRem.this, MainActivity.class);
                            startActivity(intent_ForResult);
                        }
                    })
                    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            AlertDialog alertDialog = builder.create();
            alertDialog.show();
        }
        cursor.close();
    }
}