4

Android アプリで AlertDialog ボックスを再利用します。

onCreateDialog() メソッドでダイアログを作成し、onPrepareDialog() メソッドで、次のコードを使用して PositiveButton のテキストを変更しようとしました。

alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, this.getString(R.string.add), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
          //Handler code
    }
}

onclick リスナーは変更されていますが、ボタンのテキストは変更されていません。

Androidのバグですか、それとも何か間違っていますか?

4

2 に答える 2

22

1つの解決策は、ボタンを強制的に再描画することです。たとえば、長時間の操作をキャンセルするボタンは、完了すると「OK」に変わる場合があります。

ボタンボタン=progressDialog.getButton(ProgressDialog.BUTTON1);
button.setText( "OK");
button.invalidate();
于 2010-12-02T11:52:49.513 に答える
-1

これは私のために働く

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {

        case DIALOG_ID:
            return AlertDialog.Builder(this).setTitle(R.string.contact_groups_add)
    .setView(addView).setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                        int whichButton) {

                }
            }).setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                        int whichButton) {
                }
            }).create();
    }
    return null;
}
于 2010-07-27T10:34:04.987 に答える