Note that there are some explanatory texts on larger screens.

plurals
  1. POPopup menu on click of a button in action Bar
    primarykey
    data
    text
    <p>I am trying to implement an action bar in which one of the buttons on click shows a popup menu. Here's the menu. XML (menu items in the action bar)</p> <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:id="@+id/search" android:icon="@drawable/ic_action_search" android:orderInCategory="0" android:showAsAction="always" android:title="@string/menu_search"/&gt; &lt;item android:id="@+id/refresh" android:icon="@drawable/ic_action_refresh" android:orderInCategory="1" android:showAsAction="always" android:title="@string/menu_refresh"/&gt; &lt;Item android:id="@+id/popup" android:icon="@drawable/ic_action_search" android:onClick="showPopup" android:orderInCategory="1" android:showAsAction="always" android:title="@string/menu_search" /&gt; </code></pre> <p></p> <p>I wish to show a popup menu on the click of the item having id "@+id/popup". </p> <p>here is the XML for the popup menu</p> <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:id="@+id/item1" android:icon="@drawable/ic_action_search" android:orderInCategory="0" android:showAsAction="always" android:title="@string/menu_search"/&gt; &lt;item android:id="@+id/item2" android:icon="@drawable/ic_action_search" android:orderInCategory="1" android:showAsAction="always" android:title="@string/menu_search"/&gt; </code></pre> <p></p> <p>here is the onClick method for the button</p> <pre><code>public void showPopup(View v) { PopupMenu popup = new PopupMenu(this, v); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.overflow, popup.getMenu()); popup.show(); } </code></pre> <p>And the problem is that no popup shows up on click of that button. Need help folks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload