Code example for Dialog

Methods: getWindow, onRestoreInstanceState, setOnDismissListener, show

0
        myState.dialogBundle = mDialog.onSaveInstanceState();
        return myState;
    } 
 
    private void requestInputMethod(Dialog dialog) {
        Window window = dialog.getWindow();
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    } 
 
    public void setDialogIcon(Drawable dialogIcon) {
        mDialogIcon = dialogIcon;
    } 
 
    public void setDialogIcon(int dialogIconRes) {
        mDialogIcon = getContext().getResources().getDrawable(dialogIconRes);
    } 
 
    public void setDialogLayoutResource(int dialogLayoutResId) {
        mDialogLayoutResId = dialogLayoutResId;
    } 
 
    public void setDialogMessage(CharSequence dialogMessage) {
        mDialogMessage = dialogMessage;
    } 
 
    public void setDialogMessage(int dialogMessageResId) {
        setDialogMessage(getContext().getString(dialogMessageResId));
    } 
 
    public void setDialogTitle(CharSequence dialogTitle) {
        mDialogTitle = dialogTitle;
    } 
 
    public void setDialogTitle(int dialogTitleResId) {
        setDialogTitle(getContext().getString(dialogTitleResId));
    } 
 
    public void setNegativeButtonText(CharSequence negativeButtonText) {
        mNegativeButtonText = negativeButtonText;
    } 
 
    public void setNegativeButtonText(int negativeButtonTextResId) {
        setNegativeButtonText(getContext().getString(negativeButtonTextResId));
    } 
 
    public void setPositiveButtonText(CharSequence positiveButtonText) {
        mPositiveButtonText = positiveButtonText;
    } 
 
    public void setPositiveButtonText(int positiveButtonTextResId) {
        setPositiveButtonText(getContext().getString(positiveButtonTextResId));
    } 
 
    protected void showDialog(Bundle state) {
        mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;
        mDialog = onCreateDialog(getContext());
        getPreferenceManager().registerOnActivityDestroyListener(this);
        if (state != null) {
            mDialog.onRestoreInstanceState(state);
        } 
        if (needInputMethod()) { 
            requestInputMethod(mDialog);
        } 
        mDialog.setOnDismissListener(this);
        mDialog.show();
    } 
}