I have TabActivity MainTab and all my Activities extend BasicActivity. In BasicActivity I made same menu for all Activities.
How to get access to the TabHost from BasicActivity on item menu click when Activity is’t one of the tabs?
Now I am using TabHost tabHost = (TabHost) getParent().findViewById(android.R.id.tabhost);
BUT it will work only when activity is one of the tab.
public class BasicActivity extends FragmentActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.m_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.stad:
TabHost tabHost = (TabHost) getParent().findViewById(android.R.id.tabhost);
tabHost.setCurrentTab(4);
break;
default:
return false;
}
return true;
}
}
Create a “singleton” in your TabHost and access it with TabHost.getTabHost()