Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 8 the Preference Menu. Settings... Sudoku settings s Music Play background music Hints Show hints during play We add some strings to the strings.xml.

Similar presentations


Presentation on theme: "Lecture 8 the Preference Menu. Settings... Sudoku settings s Music Play background music Hints Show hints during play We add some strings to the strings.xml."— Presentation transcript:

1 Lecture 8 the Preference Menu

2 Settings... Sudoku settings s Music Play background music Hints Show hints during play We add some strings to the strings.xml file in the values folder. These will be used in the Settings... menu.

3 right-click the menu folder, choose New->File name the new file menu.xml and insert the following xml code... <item android:id="@+id/settings" android:title="@string/settings_label" android:alphabeticShortcut="@string/settings_shortcut" /> menu.xml

4 Creating a new sub-Folder in the Resources (res) Folder <item android:id="@+id/settings" android:title="@string/settings_label" android:alphabeticShortcut="@string/settings_shortcut" />

5 @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.sudoku, menu); return true; } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } Modifying the onCreateOptionsMenu( ) Method In the Sudoku.java class, there is boolean method called onCreateOptionsMenu( ) as shown here. we modify this method in the following manner... getMenuInflater( ) returns an instance of MenuInflater that we use to read the menu definition from XML and turns it into a real view.

6 Registering the settings Activity in the Manifest

7 Example Run: Preference Menu


Download ppt "Lecture 8 the Preference Menu. Settings... Sudoku settings s Music Play background music Hints Show hints during play We add some strings to the strings.xml."

Similar presentations


Ads by Google