I have the following error when showing a PopupWindow. The errors are triggered by the line:
checkInPopup.showAtLocation((ViewGroup) mapView.getParent(), Gra
you are showing your popup too early. You may post a delayed runnable for showatlocation in Onresume , Give it a try
Edit: This post seems to have the same problem answered Problems creating a Popup Window in Android Activity
use this method before show
public static ViewGroup getActivityFirstLayout(Context ctx)
{
return (ViewGroup)((ViewGroup) ActivityMaster.getActivity(ctx).findViewById(android.R.id.content)).getChildAt(0);
}
private boolean activityIsOk(Activity activity)
{
boolean s1 = !(activity == null || activity.isFinishing());
if(s1)
{
View v = LayoutMaster.getActivityFirstLayout(activity);
return v.isShown() && ViewCompat.isLaidOut(v);
}
return false;
}
try to show popup like this
new Handler().postDelayed(new Runnable(){
public void run() {
popupWindow.showAtLocation(context.getWindow().getDecorView(), Gravity.CENTER,0,0);
}
}, 200L);
A popup's parent can't itself be a popup. Both of their parents must be the same. So, if you create a popup inside a popup, you must save the parent's popup and make it a parent.
here's an example
Same problem happened with me when i try to show popup menu in activity i also got same excpetion but i encounter problem n resolve by providing context
YourActivityName.this
instead of getApplicationContext()
at
Dialog dialog = new Dialog(getApplicationContext());
and yes it worked for me may it will help someone else