I am using fixed tabs + swipe inside a FragmentActivity. I have added a menu in action bar. I want that when the menu is clicked it should open class based on the current tab that is selected.
static TabHost myTabs;
-
-
-
myTabs = getTabHost();
This shows an error asking me if it shouls create a method called getTabHost(). I am assuming its because I am using FragmentActivity instead of Activity. So how do I know which tab is selected?
EDIT
As told below I have done this
@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;
}
But still nothing happens when I click on the menu add option.