Skip to content Skip to sidebar Skip to footer

Popup Window From Android Options Menu Not Working

Actually I am showing popup window(custom layout) when options menu item clicked and my options menu are bottom to the screen(splitActionBarWhenNarrow).I am getting some exception

Solution 1:

Try in this manner:

    switch (item.getItemId()) {
    case R.id.redid:

        Toast.makeText(MainActivity.this,"red color", Toast.LENGTH_SHORT).show();
        break;
    case R.id.blueid:
        Toast.makeText(MainActivity.this,"blue color", Toast.LENGTH_SHORT).show();
        break;
   case R.id.greenid:
        initiatePopupWindow();
        break;
   }

and outside onCreate() paste this:

private PopupWindow pwindo;

privatevoidinitiatePopupWindow() { 
try { 
// We need to get the instance of the LayoutInflater LayoutInflaterinflater= (LayoutInflater) PopupActivity.this 
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
Viewlayout= inflater.inflate(R.layout.popup,(ViewGroup)

findViewById(R.id.popup_element)); 
pwindo = newPopupWindow(layout, 350, 350, true); 
pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup); 
btnClosePopup.setOnClickListener(cancel_button_click_listener);

} catch (Exception e) { 
e.printStackTrace(); 
} 
}

I think in this manner may be your problem will be solved.

Post a Comment for "Popup Window From Android Options Menu Not Working"