Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't click Options Menu if initial menu size is zero
    primarykey
    data
    text
    <p>Lets assume, that I have two activities. One called MainActivity, and the other called PopupActivity. I want to have a context menu in MainActivity, after the user visited PopupActivity.</p> <pre><code> Main [no menu] --&gt; startActivity() / startActivityForResult() ==&gt; Popup --&gt; back / finish() ==&gt; Main [now has menu]. </code></pre> <p><strong>Environment details:</strong></p> <ul> <li>minSDK: 10 (needed for backward compatibility)</li> <li>targetSDK: 17</li> <li>targetDevice: GalaxyTab 2.0</li> </ul> <p>If the MainActivity has at least one element at the begining state, i can add / remove the desired menu items via onPrepareOptionsMenu. But if the MainActiviy has 0 menu elements inside, android doesn't even render the menu button on the top right corner. </p> <p><strong>My question is:</strong></p> <ul> <li>What do i miss? </li> <li>How to tell android, to render the menu button, because i want to add menu items to it.</li> </ul> <p>Workaround soultions can't work (like separating the Activity into two, etc.), because the whole problem is a bit more complex, but the core of it is this. I don't need menu items at the begining state, and i need them in a second one.</p> <p><strong>main_menu.xml:</strong></p> <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/menu_add" android:title="@string/add"&gt;&lt;/item&gt; &lt;item android:id="@+id/menu_remove" android:title="@string/remove" &gt;&lt;/item&gt; &lt;/menu&gt; </code></pre> <p><strong>MainActivity.java</strong></p> <pre><code>@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); return true; } @Override public boolean onPrepareOptionsMenu(Menu menu) { if (initState) { menu.findItem(R.id.menu_add).setVisible(false); menu.findItem(R.id.menu_remove).setVisible(false); } else { menu.findItem(R.id.menu_add).setVisible(true); menu.findItem(R.id.menu_remove).setVisible(true); } return super.onPrepareOptionsMenu(menu); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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