1

I want to open a PopUpWindow in another PopUpWindow. I have an ImageButtons in my MainActivity. When I click on it a PopUpWindow appears. I use it as a kind of submenu in my app. In my first PopupWindow is another ImageButton. If I click on it a second PopupWindow should appear and overlay the first one.

Opening the first PopupWindow works just fine. When I click on the button in it to open the second one, the app crashes. How can I make the second PopupWindow work?

Thanks for your help.

I tried it likes this:

final ImageButton btnOpenPopup = (ImageButton) findViewById(R.id.button_name);
        btnOpenPopup.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {

                LayoutInflater layoutInflater
                        = (LayoutInflater) getBaseContext()
                        .getSystemService(LAYOUT_INFLATER_SERVICE);

                View popupView = layoutInflater.inflate(R.layout.popup_fertig, null);

                final PopupWindow popupWindow = new PopupWindow(
                        popupView,
                        LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);

           popupWindow.showAtLocation(btnOpenPopup, Gravity.TOP | Gravity.RIGHT, 0, 0);



           Button btn_2 = (Button) popupView.findViewById(R.id.button_2);
           btn_2.setOnClickListener(new Button.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                     LayoutInflater layoutInflater_2
                        = (LayoutInflater) getBaseContext()
                        .getSystemService(LAYOUT_INFLATER_SERVICE);

                View popupView_2 = layoutInflater.inflate(R.layout.popup_2, null);

                final PopupWindow popupWindow_2 = new PopupWindow(
                        popupView_2,
                        LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);

           popupWindow_2.showAtLocation(btn_2, Gravity.TOP | Gravity.RIGHT, 0, 0);


               }
                }
            });
}
codeMagic
  • 44,549
  • 13
  • 77
  • 93
Lucy
  • 43
  • 3
  • It's hard to say without the stacktrace from the crash so you should post that. But I would make sure that `button_2` in `popupView` – codeMagic Jul 18 '15 at 14:50
  • this is called MDI (Multiple document interface). Search google how to implement MDI in java – Muhammad Imran Jul 18 '15 at 14:50
  • Uhm I'm really sorry, but I don't know how to get the stacktrace from the crash. I run the app on my actual phone and not on an emulator. Running and gradling the app is without any problems. - If it wouldn't bother, could you tell me how to get the stacktrace then? – Lucy Jul 18 '15 at 15:11
  • http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – codeMagic Jul 18 '15 at 15:22

1 Answers1

1

I'm also trying to do what you are doing but was not successful however I did figure out a workaround for what you want to do.

Inside your popupView xml layout, you would have to create a framelayout as the parent layout and then put both your popupView and popupView 2 layout within the parent layout. You would then switch on and off the visibility for each of the two layouts when a button is pressed in the popupView.

It actually works quite nicely, the popupView resizes itself appropriately according to the content it holds with smooth animations.

Simon
  • 19,658
  • 27
  • 149
  • 217