Skip to content

Commit e79d0b2

Browse files
committed
Added dummy menu items for testability
1 parent fd5896d commit e79d0b2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
<string name="app_name">MenuOptionsExample</string>
55
<string name="hello_world">Example app to show case the Menu Options an Items in Android!</string>
6+
<string name="colors">Background Color Preference</string>
7+
<string name="options">Random Options</string>
8+
<string name="quit">Quit App</string>
69
<string name="action_settings">Settings</string>
710

811
</resources>

src/com/example/menuoptions/MainActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
public class MainActivity extends Activity {
99

10+
private static final int ITEM_COLORS_ID = Menu.FIRST;
11+
private static final int ITEM_OPTIONS_ID = Menu.FIRST + 1;
12+
private static final int ITEM_QUIT_ID = Menu.FIRST + 2;
13+
1014
@Override
1115
protected void onCreate(Bundle savedInstanceState) {
1216
super.onCreate(savedInstanceState);
@@ -16,7 +20,13 @@ protected void onCreate(Bundle savedInstanceState) {
1620
@Override
1721
public boolean onCreateOptionsMenu(Menu menu) {
1822
// Inflate the menu; this adds items to the action bar if it is present.
19-
getMenuInflater().inflate(R.menu.main, menu);
23+
//getMenuInflater().inflate(R.menu.main, menu);
24+
25+
//Adding Menu Items Programatically
26+
menu.add(Menu.NONE, ITEM_COLORS_ID, Menu.NONE, R.string.colors);
27+
menu.add(Menu.NONE, ITEM_OPTIONS_ID, Menu.NONE, R.string.options);
28+
menu.add(Menu.NONE, ITEM_QUIT_ID, Menu.NONE, R.string.quit);
29+
2030
return true;
2131
}
2232

0 commit comments

Comments
 (0)