3
case IDD_SEND_SMS:
AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
builder2.setMessage("Отправить смс на номер " + number + "?");
builder2.setPositiveButton("Да",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            sendSMS(number, smsText);
        }
    });
builder2.setNegativeButton("Нет",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
builder2.setCancelable(true);
return builder2.create();

При повторном вызове сообщение остается тем же, что и было при 1-ом. Иначе говоря, setMessage во 2-ой раз не срабатывает. Почему?

1 ответ 1

3

Если этот код находится в onCreateDialog(), то проблема в том, что диалоги, созданные этим методом "кешируются". Из документации:

If you use showDialog(int), the activity will call through to this method the first time, and hang onto it thereafter. Any dialog that is created by this method will automatically be saved and restored for you, including whether it is showing.

Используйте метод onPrepareDialog() для того, чтобы изменить сообщение.

1
  • Cпасибо. Заюзал removeDialog(IDD_SEND_SMS);
    – AndroidDev
    31 окт 2011 в 8:53

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.