菜单项的代码在一个类中工作,但在其他类中不起作用

时间:2013-04-23 10:00:02

标签: android menuitem

当我在其他类中使用相同代码的菜单项时,会显示菜单。但是当我在这个类中实现然后不显示时,如果我们使用工具OnClickListener,有人能告诉我菜单项是否有任何问题

 public class MainPage extends Activity implements OnClickListener {
Context context;
ImageButton countingbutton, maximymbutton, minButton, compareButton,
        statsbutton, review, memorygmae;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newmainpage);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    countingbutton = (ImageButton) findViewById(R.id.countingbutton);
    maximymbutton = (ImageButton) findViewById(R.id.maximumbutton);
    minButton = (ImageButton) findViewById(R.id.minimunbutton);
    compareButton = (ImageButton) findViewById(R.id.comparenum);
    statsbutton = (ImageButton) findViewById(R.id.ibStats);
    review = (ImageButton) findViewById(R.id.review);
    countingbutton.setOnClickListener(this);
    maximymbutton.setOnClickListener(this);
    minButton.setOnClickListener(this);
    compareButton.setOnClickListener(this);
    statsbutton.setOnClickListener(this);
    review.setOnClickListener(this);

}
  @Override 
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate themenu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.cool_menu, menu);
  return true; 
  }


 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
     // TODO Auto-generated method stub private static final String 
     switch (item.getItemId())
     { 
     case R.id.aboutUs:
         Intent about = new Intent(this, AboutUs.class);
         startActivity(about);
         break; 

     case R.id.exit:
         super.finish(); 
         System.exit(0);
         break; 

     case R.id.mainmenu: Intent  mainmenu = new Intent(this, MainPage.class);
        startActivity(mainmenu);
        break;
     }
 return false;
 } 

0 个答案:

没有答案