Search code examples
androidpopuppopupwindowdialogfragment

Popup appears behind DialogFragment


I have a DialogFragment. On tapping a button in this Dialog fragment I need to display a pop up window above a particular edittext in the dialog fragment. To do this I find the absolute co-ordinates of the edittext using

int[] coords = {0,0};
editText.getLocationOnScreen(coords);

and display the popup at the required location using

popup.showAtLocation(popupView, Gravity.NO_GRAVITY, coords[0] + edittext.getWidth(), coords[1]);

But doing this displays the pop up window behind the dialog fragment. Is there any way to get the pop up above the dialog fragment?


Solution

  • Okay, I figured out my mistake. The first parameter for popUp.showAtLocation should be getView() instead of popUpView.

    popup.showAtLocation(getView(), Gravity.NO_GRAVITY, coords[0] + edittext.getWidth(), coords[1]);
    

    This now draws the popup above the dialogFragment