对话框不会在方向更改时重新创建

时间:2011-07-11 15:32:44

标签: android dialog orientation

使用:

调用

的ShowDialog(DIALOG_LONG_CLICK_MENU_ID);

在方向更改时泄漏窗口没有问题但是当重新创建活动时,永远不会调用onCreateDialog或onPrepareDialog?

不知道它是否有任何区别,但活动是在标签内。

对可能的任何见解都会受到大力赞赏!

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;
    CURRENT_DIALOG = id;
    switch(id) {
        case DIALOG_LONG_CLICK_MENU_ID:
            dialog = displayItemLongClickMenu();
            break;
        default:
            CURRENT_DIALOG = DIALOG_NONE_ID; 
            dialog = null;
            break;
        }
    return dialog;
}    


private Dialog displayItemLongClickMenu() {
    AlertDialog alertDialog;
    AlertDialog.Builder builder;
    builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.activity_item_dialog_title);
    // save index and top position          
    mIndex = getListView().getFirstVisiblePosition();
    View vLC = getListView().getChildAt(0);
    mTop = (vLC == null) ? 0 : vLC.getTop();        

    builder.setItems(new String[]{ getString(R.string.delete)},
                     new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            final PomodoroApp pA = ((PomodoroApp)getApplicationContext());              
            switch (which){
            case DELETE_ID: 
                mDbHelper.deleteActivity(mItemListDialogId);
                refactorToDoList();
                dialog.dismiss();
                break;
            default:
                break;
            }
        }
    });
    alertDialog = builder.create();
    alertDialog.setCancelable(true);
    return(alertDialog);
}

0 个答案:

没有答案