好吧,我在 A 类中有一个菜单方法,单击时会在模拟器中显示菜单。
如何将该方法用于我的新 B 类
我希望 B 类也可以使用这种方法:
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
//inflates the menu or this will show the activity
MenuInflater awesome = getMenuInflater();
awesome.inflate(R.menu.main, menu); //main is the xml main
return true;
}
//this will manipulate the menu
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.menuSweet:
startActivity(new Intent("Sweet"));
return true;
case R.id.menuToast:
Toast andEggs = Toast.makeText(MainActivity.this,
"This is a toast", Toast.LENGTH_LONG);
andEggs.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}