How to show Popup Window in Android. I am using below code but it give fatal exception.

Total Post:13

Points:93
 971  View(s)
Ratings:
Rate this:
  PopupWindow popupWindow = new PopupWindow(getApplicationContext());
        
        // inflate your layout or dynamically add view
        LayoutInflater inflater = (LayoutInflater) getWindow().getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.my_layout, null);
        popupWindow.setFocusable(true);
        popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setContentView(view);      
        popupWindow.showAsDropDown(v);
  1. Post:26

    Points:188
    Re: How to show Popup Window in Android. I am using below code but it give fatal exception.

     Hi Linda

     Use below code
     PopupWindow popupWindow = new PopupWindow(getWindow().getContext());

    instead of
     PopupWindow popupWindow = new PopupWindow(getApplicationContext());

      Modified On Apr-11-2018 04:34:11 AM

Answer