我正在使用固定标签+在FragmentActivity内滑动。我在操作栏中添加了一个菜单。我希望当单击菜单时,它应该根据所选的当前选项卡打开类。
static TabHost myTabs;
-
-
-
myTabs = getTabHost();这显示了一个错误,询问它是否应该创建一个名为getTabHost()的方法。我假设这是因为我使用的是FragmentActivity而不是活动。那么,我如何知道选择了哪个选项卡?
编辑
如下所示,我做了这件事
@Override
public void onAttachFragment(Fragment fragment){
super.onAttachFragment(fragment);
tabValue=fragment.getId();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.one, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (tabValue) {
case 0:
Toast.makeText(BarcodeActivity.this, "HELLO", Toast.LENGTH_LONG).show();
case 1:
Intent i = new Intent(BarcodeActivity.this, NewCodeAdder.class);
startActivity(i);
break;
}
return true;
}但是,当我单击菜单添加选项时,仍然不会发生任何事情。
发布于 2013-12-27 15:42:04
看看这个,它包含了从id到查找选项卡名称的所有内容:
https://stackoverflow.com/questions/20803214
复制相似问题