Sunday, 15 April 2012

android - Why opens popupmenu inside action bar -


I'm working on a timetable app, but I have a strange problem, I made a Popapmenu which an action Opens at clicking - Bar item.

Popup works, but it opens inside the action bar , I want it to open in the bottom view.

enter image description here

My code .. < / p>

  @Override public create the Option menu zero (menu, menu Infletr Inflatr) {inflater.inflate (R.menu.lists_choice_mode_mulitplue, menu); } @ Override Crate on Public Zero (Bundle Saved Instantstate) {Super.Nought (Saved Instantstate); SetHasOptionsMenu (true); } @ Override selected public boolean on option Itam (Menuitm item) {// handle item selection list (Aitet. Get Aitimaidi ()) {case R. Indivir: Show popup menu (this. GetView ()); Back true; } return false; } Private Zero Show popup menu (see V) {last activity activity = getSupportActivity (); Popup menu popup menu = new popup menu (Activity, V); PopupMenu.getMenuInflater (). Flood (r menu, popup, popupMenu.getMenu ()); PopupMenuksetOnMenuItemClickListener (new Popapmenu. OnMenuItemClickListener () {Do @Override public boolean Prmenuitemklik (Menuitm item) {toast. Mektekst (action items. Tosting (), toast. LNGTH_LONG). Show (); return true;}}); PopupMenu.show (); }   

My .xml layout files

popup.xml

  & lt ;? Xml version = "1.0" encoding = "UTF-8" & gt; & Lt; Menu xmlns: Android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Group Android: id = "@ + id / group_popupmenu" & gt; & Lt; Android Android: id = "@ + id / menu1" Android: title = "popup menu item 1" /> & Lt; Item Android: id = "@ + ID / Menu 2" Android: Title = "Popup Menu Item 2" /> & Lt; Android Android: id = "@ + id / menu3" Android: title = "popup menu item 3" /> & Lt; / Groups & gt; & Lt; / Menu & gt;   

My Action Bar button .xml

     

Yes, it has to be fixed!

To show popup menu its wrong (This.getView ());

It should be ID icon in the action bar .. as follows ..

  @Override public boolean Onoptsitm selected (Menuitm item) {// handle item selection Switch (item.getItemId ()) {case R.id.inverse: showPopupMenu (R.id.inverse); Back true; } return false; }   

showpopupmenu (See v) in

  private void show pop-up menu (Int id) {final activity = getSupportActivity (); See v = activity.findViewById (ID); Popup menu popup menu = new popup menu (Activity, V); PopupMenu.getMenuInflater (). Flood (r menu, popup, popupMenu.getMenu ()); PopupMenuksetOnMenuItemClickListener (new Popapmenu. OnMenuItemClickListener () {Do @Override public boolean Prmenuitemklik (Menuitm item) {toast. Mektekst (action items. Tosting (), toast. LNGTH_LONG). Show (); return true;}}); PopupMenu.show (); }   

It works now! Thanks for the answers did not help me, but you appreciate went!

No comments:

Post a Comment