Home > DeveloperSection > Forums > How to show Popup Window in Android. I am using below code but it give fatal exception.
Linda Perla
Linda Perla

Total Post:13

Points:93
Posted on    June-14-2016 11:52 PM

 Android Android 
Ratings:


 1 Reply(s)
 175  View(s)
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);


Manoj Pandey

Total Post:26

Points:188
Posted on    June-15-2016 1:43 AM

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

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

Don't want to miss updates? Please click the below button!

Follow MindStick