mTabHost.setOnTabChangedListener(listener); mTabHost.setup();
@Test public void shouldFireTheTabChangeListenerWhenCurrentTabIsSet() throws Exception { TabHost tabHost = new TabHost(context); TabHost.TabSpec foo = tabHost.newTabSpec("Foo"); TabHost.TabSpec bar = tabHost.newTabSpec("Bar"); TabHost.TabSpec baz = tabHost.newTabSpec("Baz"); tabHost.addTab(foo); tabHost.addTab(bar); tabHost.addTab(baz); TestOnTabChangeListener listener = new TestOnTabChangeListener(); tabHost.setOnTabChangedListener(listener); tabHost.setCurrentTab(2); assertThat(listener.tag).isEqualTo("Baz"); }
@Test public void shouldFireTheTabChangeListenerWhenTheCurrentTabIsSetByTag() throws Exception { TabHost tabHost = new TabHost(context); TabHost.TabSpec foo = tabHost.newTabSpec("Foo"); TabHost.TabSpec bar = tabHost.newTabSpec("Bar"); TabHost.TabSpec baz = tabHost.newTabSpec("Baz"); tabHost.addTab(foo); tabHost.addTab(bar); tabHost.addTab(baz); TestOnTabChangeListener listener = new TestOnTabChangeListener(); tabHost.setOnTabChangedListener(listener); tabHost.setCurrentTabByTag("Bar"); assertThat(listener.tag).isEqualTo("Bar"); }
public TabManager(final FragmentActivity activity, final TabHost tabHost, final int containerId) { mActivity = activity; mTabHost = tabHost; mContainerId = containerId; mTabHost.setOnTabChangedListener(this); }
private void initFragmentTabHost(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0); mContainerId = a.getResourceId(0, 0); a.recycle(); super.setOnTabChangedListener(this); }
private void initFragmentTabHost(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0); mContainerId = a.getResourceId(0, 0); a.recycle(); super.setOnTabChangedListener(this); }
private void initFragmentTabHost(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.inflatedId}, 0, 0); mContainerId = a.getResourceId(0, 0); a.recycle(); super.setOnTabChangedListener(this); }
private void initFragmentTabHost(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0); mContainerId = a.getResourceId(0, 0); a.recycle(); super.setOnTabChangedListener(this); }
public TabHost handleCreateView(View root) { if (mTabHost != null) { throw new IllegalStateException("TabHost already set"); } mTabHost = (TabHost)root.findViewById(android.R.id.tabhost); mTabHost.setup(); mTabHost.setOnTabChangedListener(this); return mTabHost; }
public TabsAdapter(FragmentActivity activity, TabHost tabHost, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mTabHost = tabHost; mViewPager = pager; mTabHost.setOnTabChangedListener(this); mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); dummyTabFactory = new DummyTabFactory(activity); }
public TabHost handleCreateView(View root) { if (mTabHost != null) { throw new IllegalStateException("TabHost already set"); } mTabHost = (TabHost)root.findViewById(android.R.id.tabhost); mTabHost.setup(); mTabHost.setOnTabChangedListener(this); return mTabHost; }
public class MainActivity extends Activity implements OnTabChangeListener { TabHost myTabHost; @Override protected void onCreate(Bundle savedInstanceState) { ... myTabHost.setOnTabChangedListener(this); } ... @Override public void onTabChanged(String arg0) { myTabHost.getCurrentTab(); } }
private TabHost mTabHost; public PopupMenu popupMenu; /* A HashMap of stacks, where we use tab identifier as keys.. */ private HashMap<String, Stack<Fragment>> mStacks; /* Save current tabs identifier in this.. */ private String mCurrentTab; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tabhost); mStacks = new HashMap<String, Stack<Fragment>>(); mStacks.put("TAB1", new Stack<Fragment>()); mStacks.put("TAB2", new Stack<Fragment>()); mStacks.put("TAB3", new Stack<Fragment>()); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); mTabHost.setOnTabChangedListener(listener); initializeTabs();
mlam = new LocalActivityManager(this, false); final TabHost tabHost = (TabHost) findViewById(R.id.tabhostfaces); mlam.dispatchCreate(bundle); mlam.dispatchResume(); mlam.dispatchPause(isFinishing()); tabHost.setup(mlam); tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { String currentTag = mTabHost.getCurrentTabTag(); if(currentTag.equals("tab_ntflist")){ ntfreglst.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); mlam.startActivity(currentTag, new Intent(ntfreglst)); } else if(currentTag.equals("tab_profile")){ pflvw.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); mlam.startActivity(currentTag, new Intent(pflvw)); } } });
private void initTabHost(final Bundle args) { final TabHost th = (TabHost) findViewById(android.R.id.tabhost); th.setup(); // I have a HashMap called fragMap where as the key I define the tab's name // And as the value, I have an Integer which is a unique identifier // to know what to inflate when I call the TabFragmentInflater (I will // add the code below). You can perfectly add it as an id or a tag also. for (final String tablabel : fragMap.keySet()) { final TabHost.TabSpec tabSpec = th.get().newTabSpec(tabname).setIndicator(tabname); // Here I initialize a TabInfo object for this tab, which will include additional // Handling info: Name of tab, Tab Spec, The unique ID I explained above, // the forth argument is irrelevant in your example, and args (saved instance) final TabInfo tabInfo = new TabInfo(tabname, tabSpec, fragMap.get(tablabel), R.id.someLayout, args); // This is not actually the TabHost's `addTab()` method, I'll call it inside // this method (see below) MyClass.addTab(this, th, tabSpec, tabInfo); // I have to be able to keep tracking of that info mTabInfo.put(tabInfo.getTag(), tabInfo); } // For the tab creation, I force it to start on the first tab this.onTabChanged(firstTabNameTag); th.setOnTabChangedListener(this); }
public class Main extends TabActivity implements OnTabChangeListener { TabHost tabHost; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tabHost = getTabHost(); tabHost.getTabWidget().setStripEnabled(false); tabHost.setOnTabChangedListener((OnTabChangeListener) this); TabSpec spec1 = tabHost.newTabSpec("Indoor"); //below sets the text and image on the tab spec1.setIndicator("", getResources().getDrawable(R.drawable.indoorImage)); Intent intIndoor = new Intent(this, Indoor.class); spec1.setContent(intIndoor); TabSpec spec2 = tabHost.newTabSpec("Outdoor"); //below sets the text and image on the tab spec2.setIndicator("Outdoor", getResources().getDrawable(R.drawable.outdoorImage)); Intent intOutdoor = new Intent(this, Outdoor.class); spec2.setContent(intOutdoor); tabHost.addTab(spec1); tabHost.addTab(spec2); }
//setting up the tabs res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab intent = new Intent().setClass(this, First.class); spec = tabHost.newTabSpec("one").setIndicator("One") .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, Second.class); spec = tabHost.newTabSpec("two").setIndicator("Two") .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String arg0) { // TODO Auto-generated method stub setTabColor(tabHost); } }); setTabColor(tabHost);
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); TabHost.TabSpec tabSpec; tabSpec = tabHost.newTabSpec("1"); tabSpec.setIndicator("Tab"); tabSpec.setContent(R.id.list_fragment); tabHost.addTab(tabSpec); tabHost.setOnTabChangedListener(listener);
/** * A method which initializes editor and preview tabs. */ private void initTabs() { tabHost.setup(); TabHost.TabSpec tabSpec = tabHost.newTabSpec(EDITOR_TAB_ID); tabSpec.setContent(R.id.tab_editor); tabSpec.setIndicator(EDITOR_TAB_ID); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec(PREVIEW_TAB_ID); tabSpec.setContent(R.id.tab_preview); tabSpec.setIndicator(PREVIEW_TAB_ID); tabHost.addTab(tabSpec); tabHost.setOnTabChangedListener(tabId -> hideSoftKeyboard()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); greenRobotBus = GreenRobotBus_.getInstance_(this); requestWindowFeature(Window.FEATURE_NO_TITLE); initialLoad(); final TabHost tabHost = getTabHost(); setupAccountsTab(tabHost); setupBlotterTab(tabHost); setupBudgetsTab(tabHost); setupReportsTab(tabHost); setupMenuTab(tabHost); MyPreferences.StartupScreen screen = MyPreferences.getStartupScreen(this); tabHost.setCurrentTabByTag(screen.tag); tabHost.setOnTabChangedListener(this); }