0

I have a layout that I want to show as a popup window (used as a custom options menu) while in a fragment of a viewpager. Therefore, when the "Options" button is clicked, I do the following:

    public void onOptionsButtonClicked(int buttonHeight)
    {
        LayoutInflater optionsLayoutInflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);
        int popupWidth = ViewGroup.LayoutParams.MatchParent;
        int popupHeight = ViewGroup.LayoutParams.WrapContent;

        View layout = optionsLayoutInflater.Inflate(Resource.Layout.TrackOptions, null);

        int popupYOffset = (85 + buttonHeight) * -1;

        var popup = new PopupWindow(context);
        popup.Focusable = true;
        popup.Width = popupWidth;
        popup.Height = popupHeight;
        popup.ContentView = layout;
        popup.SetBackgroundDrawable(new BitmapDrawable());
        popup.OutsideTouchable = true;
        popup.ShowAsDropDown(view, 0, popupYOffset);


    }

And this works as I want, visually that is. Meaning, I click the button and I do see the layout popup as a popup window with all of my options. HOWEVER, none of the buttons work. I put a breakpoint in the class that should be associated the the layout and noticed that onCreateView never gets called, therefore, none of the buttons and associated click event handlers are ever wired up. So, I know why it is not working. However, I don't know how to fix it. I think it is because, while I inflate the view, I am never actually creating the fragment. I have done fragementmanager transactions to replace a fragment in other parts of my project and I know that would probably do it, however, this is a different case as I am trying to do a popup window.

Thanks!

Mike

Michael Bedford
  • 1,742
  • 20
  • 48
  • Maybe [this](http://stackoverflow.com/questions/18461990/pop-up-window-to-display-some-stuff-in-a-fragment) will help? – Code-Apprentice Aug 16 '16 at 00:27
  • No, that is basically what I already have now and posted in my thread. That is inflating the layout but what about the entire fragment class I have? How to I "inflate" that as well so that onCreateView is called? – Michael Bedford Aug 16 '16 at 01:34
  • The wiring up of the buttons in the `TrackOptions` layout need to happen right in the `onOptionsButtonClicked` method...e.g. `Button btn = (Button) layout.findViewById(R.id.btn); ...code to write it up...`...If you want to show a fragment and have it's OnCreateView called, then you have to do a fragment transaction. – pnavk Aug 16 '16 at 02:22

1 Answers1

0

Fragment is attach in activity so you can try it in onActivityCreated(Bundle) method

Long Ranger
  • 5,888
  • 8
  • 43
  • 72
zhang
  • 41
  • 2