01.
package
com.myapp;
02.
03.
import
android.os.Bundle;
04.
import
android.app.Activity;
05.
import
android.view.Menu;
06.
import
android.view.MenuItem;
07.
import
android.widget.TextView;
08.
import
android.widget.Toast;
09.
10.
public
class
MainActivity
extends
Activity {
11.
12.
@Override
13.
public
void
onCreate(Bundle savedInstanceState) {
14.
super
.onCreate(savedInstanceState);
15.
setContentView(R.layout.activity_main);
16.
17.
18.
final
TextView txt = (TextView) findViewById(R.id.textView1);
19.
txt.setText(
"Click Button Menu to Show Menu"
);
20.
}
21.
22.
@Override
23.
public
boolean
onCreateOptionsMenu(Menu menu) {
24.
getMenuInflater().inflate(R.menu.activity_menu, menu);
25.
return
true
;
26.
}
27.
28.
@Override
29.
public
boolean
onOptionsItemSelected(MenuItem item)
30.
{
31.
switch
(item.getItemId())
32.
{
33.
case
R.id.menu1:
34.
Toast.makeText(MainActivity.
this
,
"Your Click Menu 1"
, Toast.LENGTH_SHORT).show();
35.
return
true
;
36.
37.
case
R.id.menu2:
38.
Toast.makeText(MainActivity.
this
,
"Your Click Menu 2"
, Toast.LENGTH_SHORT).show();
39.
return
true
;
40.
41.
case
R.id.menu3:
42.
Toast.makeText(MainActivity.
this
,
"Your Click Menu 3"
, Toast.LENGTH_SHORT).show();
43.
return
true
;
44.
45.
default
:
46.
return
super
.onOptionsItemSelected(item);
47.
}
48.
49.
50.
}
51.
52.
}