Android系列之UI组件----Menu菜单
当菜单第一次被加载时调用
20 @Override
21 public boolean onCreateOptionsMenu(Menu menu) {
22 // Inflate the menu; this adds items to the action bar if it is present.
23 //填充选项菜单(读取XML文件、解析、加载到Menu组件上)
24 getMenuInflater().inflate(R.menu.main, menu);
25 return true;
26 }
27
28 //重写OptionsItemSelected(MenuItem item)来响应菜单项(MenuItem)的点击事件(根据id来区分是哪个item)
29 @Override
30 public boolean onOptionsItemSelected(MenuItem item) {
31 // Handle action bar item clicks here. The action bar will
32 // automatically handle clicks on the Home/Up button, so long
33 // as you specify a parent activity in AndroidManifest.xml.
34 switch (item.getItemId()) {
35 case R.id.start:
36 Toast.makeText(this, 开始游戏, Toast.LENGTH_SHORT).show();
37 break;
38 case R.id.over:
39 Toast.makeText(this, 结束游戏, Toast.LENGTH_SHORT).show();
40 break;
41
42 default:
43 break;
44 }
45 return super.onOptionsItemSelected(item);
46 }
47 }
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)