Methods Summary |
---|
public void | addTab(android.widget.TabHost$TabSpec tabSpec)Add a tab.
if (tabSpec.mIndicatorStrategy == null) {
throw new IllegalArgumentException("you must specify a way to create the tab indicator.");
}
if (tabSpec.mContentStrategy == null) {
throw new IllegalArgumentException("you must specify a way to create the tab content");
}
View tabIndicator = tabSpec.mIndicatorStrategy.createIndicatorView();
tabIndicator.setOnKeyListener(mTabKeyListener);
mTabWidget.addView(tabIndicator);
mTabSpecs.add(tabSpec);
if (mCurrentTab == -1) {
setCurrentTab(0);
}
|
public void | clearAllTabs()Removes all tabs from the tab widget associated with this tab host.
mTabWidget.removeAllViews();
initTabHost();
mTabContent.removeAllViews();
mTabSpecs.clear();
requestLayout();
invalidate();
|
public boolean | dispatchKeyEvent(android.view.KeyEvent event)
final boolean handled = super.dispatchKeyEvent(event);
// unhandled key ups change focus to tab indicator for embedded activities
// when there is nothing that will take focus from default focus searching
if (!handled
&& (event.getAction() == KeyEvent.ACTION_DOWN)
&& (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP)
&& (mCurrentView.isRootNamespace())
&& (mCurrentView.hasFocus())
&& (mCurrentView.findFocus().focusSearch(View.FOCUS_UP) == null)) {
mTabWidget.getChildAt(mCurrentTab).requestFocus();
playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
return true;
}
return handled;
|
public void | dispatchWindowFocusChanged(boolean hasFocus)
mCurrentView.dispatchWindowFocusChanged(hasFocus);
|
public int | getCurrentTab()
return mCurrentTab;
|
public java.lang.String | getCurrentTabTag()
if (mCurrentTab >= 0 && mCurrentTab < mTabSpecs.size()) {
return mTabSpecs.get(mCurrentTab).getTag();
}
return null;
|
public android.view.View | getCurrentTabView()
if (mCurrentTab >= 0 && mCurrentTab < mTabSpecs.size()) {
return mTabWidget.getChildAt(mCurrentTab);
}
return null;
|
public android.view.View | getCurrentView()
return mCurrentView;
|
public FrameLayout | getTabContentView()Get the FrameLayout which holds tab content
return mTabContent;
|
public TabWidget | getTabWidget()
return mTabWidget;
|
private final void | initTabHost()
setFocusableInTouchMode(true);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
mCurrentTab = -1;
mCurrentView = null;
|
private void | invokeOnTabChangeListener()
if (mOnTabChangeListener != null) {
mOnTabChangeListener.onTabChanged(getCurrentTabTag());
}
|
public android.widget.TabHost$TabSpec | newTabSpec(java.lang.String tag)Get a new {@link TabSpec} associated with this tab host.
return new TabSpec(tag);
|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
final ViewTreeObserver treeObserver = getViewTreeObserver();
if (treeObserver != null) {
treeObserver.addOnTouchModeChangeListener(this);
}
|
protected void | onDetachedFromWindow()
super.onDetachedFromWindow();
final ViewTreeObserver treeObserver = getViewTreeObserver();
if (treeObserver != null) {
treeObserver.removeOnTouchModeChangeListener(this);
}
|
public void | onTouchModeChanged(boolean isInTouchMode){@inheritDoc}
if (!isInTouchMode) {
// leaving touch mode.. if nothing has focus, let's give it to
// the indicator of the current tab
if (!mCurrentView.hasFocus() || mCurrentView.isFocused()) {
mTabWidget.getChildAt(mCurrentTab).requestFocus();
}
}
|
public void | setCurrentTab(int index)
if (index < 0 || index >= mTabSpecs.size()) {
return;
}
if (index == mCurrentTab) {
return;
}
// notify old tab content
if (mCurrentTab != -1) {
mTabSpecs.get(mCurrentTab).mContentStrategy.tabClosed();
}
mCurrentTab = index;
final TabHost.TabSpec spec = mTabSpecs.get(index);
// Call the tab widget's focusCurrentTab(), instead of just
// selecting the tab.
mTabWidget.focusCurrentTab(mCurrentTab);
// tab content
mCurrentView = spec.mContentStrategy.getContentView();
if (mCurrentView.getParent() == null) {
mTabContent
.addView(
mCurrentView,
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
}
if (!mTabWidget.hasFocus()) {
// if the tab widget didn't take focus (likely because we're in touch mode)
// give the current tab content view a shot
mCurrentView.requestFocus();
}
//mTabContent.requestFocus(View.FOCUS_FORWARD);
invokeOnTabChangeListener();
|
public void | setCurrentTabByTag(java.lang.String tag)
int i;
for (i = 0; i < mTabSpecs.size(); i++) {
if (mTabSpecs.get(i).getTag().equals(tag)) {
setCurrentTab(i);
break;
}
}
|
public void | setOnTabChangedListener(android.widget.TabHost$OnTabChangeListener l)Register a callback to be invoked when the selected state of any of the items
in this list changes
mOnTabChangeListener = l;
|
public void | setup()Call setup() before adding tabs if loading TabHost using findViewById(). However: You do
not need to call setup() after getTabHost() in {@link android.app.TabActivity TabActivity}.
Example:
mTabHost = (TabHost)findViewById(R.id.tabhost);
mTabHost.setup();
mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
mTabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
if (mTabWidget == null) {
throw new RuntimeException(
"Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'");
}
// KeyListener to attach to all tabs. Detects non-navigation keys
// and relays them to the tab content.
mTabKeyListener = new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_ENTER:
return false;
}
mTabContent.requestFocus(View.FOCUS_FORWARD);
return mTabContent.dispatchKeyEvent(event);
}
};
mTabWidget.setTabSelectionListener(new TabWidget.OnTabSelectionChanged() {
public void onTabSelectionChanged(int tabIndex, boolean clicked) {
setCurrentTab(tabIndex);
if (clicked) {
mTabContent.requestFocus(View.FOCUS_FORWARD);
}
}
});
mTabContent = (FrameLayout) findViewById(com.android.internal.R.id.tabcontent);
if (mTabContent == null) {
throw new RuntimeException(
"Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'");
}
|
public void | setup(android.app.LocalActivityManager activityGroup)If you are using {@link TabSpec#setContent(android.content.Intent)}, this
must be called since the activityGroup is needed to launch the local activity.
This is done for you if you extend {@link android.app.TabActivity}.
setup();
mLocalActivityManager = activityGroup;
|