Note that there are some explanatory texts on larger screens.

plurals
  1. POmy android code for creating and using the menu does not work as it should
    primarykey
    data
    text
    <p>I am a new bee to <i>Android App Development</i>. I am practicing the code in the Book <i>Hello, Android </i>. Right now I am struck with <i>Menu</i> and could not able to move further. I would like to present my situation in clear so that I could be guided by an experienced <i>android app developer </i>. I uploaded a picture showing the status. when I pressed the <b>menu</b> I could able to find one option called <b>settings.</b></p> <p>But nothing happens when the <b>settings</b> button is pressed. I am surprised about the error and wasted lot of time to fix it. but I could not able to fix it. I want some real android app development professional to find the solution to this problem that I face and help me to proceed further. </p> <p><img src="https://i.stack.imgur.com/2Xtf3.jpg" alt="enter image description here"></p> <p>here is the code that i used.</p> <p><b>test/src/org/anil/test/TestActivity.java</b></p> <pre><code> package org.anil.test; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.content.Intent; public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public boolean onCreateOptionsMenu(Menu menu){ super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } public boolean onOptionsMenuSelected( MenuItem item){ switch(item.getItemId()){ case R.id.settings: startActivity(new Intent(this, Prefs.class)); return true; } return false; } } </code></pre> <p><b>test/res/layout/main.xml</b></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;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><b>test/src/org/anil/test/Prefs.java</b></p> <pre><code> package org.anil.test; import android.os.Bundle; import android.preference.PreferenceActivity; public class Prefs extends PreferenceActivity { protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); } } </code></pre> <p><b>test/res/menu/menu.xml</b></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/settings" android:title="@string/settings_label" android:alphabeticShortcut="@string/settings_shortcut" /&gt; &lt;/menu&gt; </code></pre> <p><b>test/res/xml/settings.xml</b></p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;CheckBoxPreference android:key="music" android:title="@string/music_title" android:summary="@string/music_summary" android:defaultValue="true" /&gt; &lt;CheckBoxPreference android:key="hints" android:title="@string/hints_title" android:summary="@string/hints_summary" android:defaultValue="true"/&gt; &lt;/PreferenceScreen&gt; </code></pre> <p><b>test/res/values/strings.xml</b></p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="hello"&gt;Hello World, TestActivity!&lt;/string&gt; &lt;string name="app_name"&gt;Test&lt;/string&gt; &lt;string name="settings_label"&gt;Settings&lt;/string&gt; &lt;string name="settings_title"&gt;Sudoku Settings&lt;/string&gt; &lt;string name="settings_shortcut"&gt;s&lt;/string&gt; &lt;string name="music_title"&gt;Music&lt;/string&gt; &lt;string name="music_summary"&gt;play background music&lt;/string&gt; &lt;string name="hints_title"&gt;Hints&lt;/string&gt; &lt;string name="hints_summary"&gt;Show hints during play&lt;/string&gt; &lt;/resources&gt; </code></pre> <p><b>test/AndroidManifest.xml</b></p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.anil.test" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="10" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".TestActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".Prefs" android:label="@string/settings_title"&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    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.
 

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