Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid onCreateOptionMenu not being called
    primarykey
    data
    text
    <p>I am implementing an Android Activity from which other Activities will be derived from. So basically I have this setup of an InventoryActivity and its parent class, ListActivity:</p> <pre><code>public class MyListActivity extends Activity { protected Context mContext; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this.getBaseContext(); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.options, menu); Log.d("Creating options menu", "True"); return true; } @Override public boolean onPrepareOptionsMenu(Menu menu) { Log.d("Preparing options menu", "True"); return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.save: return(true); case R.id.revert: return(true); } return(super.onOptionsItemSelected(item)); } } public class InventoryActivity extends MyListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.inventory); } } </code></pre> <p>And I also have this in options.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/card_list_save" android:icon="@drawable/ic_menu_save" android:title="Save"/&gt; &lt;item android:id="@+id/card_list_revert" android:icon="@drawable/ic_menu_revert" android:title="Revert" /&gt; &lt;/menu&gt; </code></pre> <p>If necessary, this is my layout for inventory.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/callSearch" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Search"/&gt; &lt;ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/inventory"/&gt; &lt;/ScrollView&gt; &lt;/LinearLayout&gt; </code></pre> <p>However, when I press the menu button, nothing happens. The Log messages in the onCreateOptionsMenu method does not appear. Instead all I can see is the following:</p> <pre><code>02-04 11:36:58.313: W/KeyCharacterMap(31464): No keyboard for id 0 02-04 11:36:58.313: W/KeyCharacterMap(31464): Using default keymap: /system/usr/keychars/qwerty.kcm.bin </code></pre> <p>But what baffles me the most is that this code works in other Activities, such as my launcher Activity. But by the concept of object oriented programming, the InventoryActivity should call the overriding methods in the MyListActivity. I am completely stuck and I need help.</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.
    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