Android: AlertDialog closes only after second click on any button
<p>I have an alert dialog with input field and two buttons (revert, save).
When I click "back" button on my phone, I want another confirmation dialog to popup asking: "Are you sure you want to finish?". So it all looks like this:</p>

<pre><code>public void showNewItemDialog(final int...position) {
    LayoutInflater li = LayoutInflater.from(HostActivity.this);
    View promptsView = li.inflate(R.layout.item_dialog, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            HostActivity.this);
    alertDialogBuilder.setView(promptsView);
    userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput);
    if(position.length&gt;0){
        userInput.setText(listFragment.getmItems().get(position[0]).getTitle());
        userInput.setSelection(userInput.length());
        userInput.requestFocus();
    }
    alertDialogBuilder
            .setCancelable(false)
            .setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            String title = userInput.getText().toString();
                            if(listFragment.getItemClickType() == Utility.ItemClick.SHORT){
                                listFragment.editRowItem(title, position[0]);
                            }else if(listFragment.getItemClickType() == Utility.ItemClick.LONG){

                            }else if(listFragment.getItemClickType() == Utility.ItemClick.ADD_BUTTON){
                                listFragment.addRowItem(title);
                            }

                        }
                    })
            .setNegativeButton("Revert",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
    newItemalertDialog = alertDialogBuilder.create();

    newItemalertDialog.setOnKeyListener(new Dialog.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface arg0, int keyCode,
                             KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                new AlertDialog.Builder(HostActivity.this)
                        .setIcon(android.R.drawable.ic_dialog_alert)
                        .setTitle("Add Item")
                        .setMessage("Are you sure you want to finish?")
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                newItemalertDialog.dismiss();
                            }
                        }).setNegativeButton("No", null).show();
            }
            return false;
        }
    });
    newItemalertDialog.show();
}
</code></pre>

<p>It all works, but the second confirmation dialog closes only after I tap two times at any button (No, Yes).
I can't seem to find the cause of this. 
Thank you.</p>