RW6
RW6

Reputation: 59

How to use a dialogue box within a popup window?

I have a popup window that gets executed when a button is pressed. When the user clicks "home" within the popup window I want a dialogue message to pop up asking the user if they are sure they want to quit.

Here is how I declare the popup window:

            LayoutInflater inflater = (LayoutInflater) endlessflags.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = inflater.inflate(R.layout.success_menu, (ViewGroup) findViewById(R.id.myPop5));

            pwindo4 = new PopupWindow(layout, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
            pwindo4.setAnimationStyle(R.style.AnimationPopup);
            pwindo4.showAtLocation(layout, Gravity.TOP | Gravity.CENTER, 0, 0);

And then I have a onTouchListener for the button that are also called in the popup window. I try to call the dialogue function I created but when I do nothing happens and I get no errors or crashes:

        AlertDialog.Builder myAlert = new AlertDialog.Builder(mainActivity.this);
        myAlert.setMessage("Would you like to quit?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            saveState = true;
            saveState();
            //finish();
            dialog.cancel();
        }
        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            saveState = false;
            dialog.cancel();
            }
        });

My question is why is it that when I call the dialogue event function nothing seems to happen and how can I fix this so the dialogue box shows up when I click a button within my popup window?

Upvotes: 0

Views: 56

Answers (1)

RobVoisey
RobVoisey

Reputation: 1083

You need to show the dialog:

AlertDialog dialog = myAlert.create();
dialog.show();

Upvotes: 1

Related Questions