diff options
author | Bjorn Bringert <bringert@android.com> | 2009-12-10 15:58:49 +0000 |
---|---|---|
committer | Bjorn Bringert <bringert@android.com> | 2009-12-11 15:48:31 +0000 |
commit | acdef59d66094f11da4a6f57194747dc06f73da2 (patch) | |
tree | a685afe530f3b7d4442db31090ac37af746620e1 /core/java | |
parent | 159f0015418955501d8cf2744b0393db2e73f394 (diff) | |
download | frameworks_base-acdef59d66094f11da4a6f57194747dc06f73da2.zip frameworks_base-acdef59d66094f11da4a6f57194747dc06f73da2.tar.gz frameworks_base-acdef59d66094f11da4a6f57194747dc06f73da2.tar.bz2 |
Fix TabHost NPE when there are no tabs
Fixes http://b/issue?id=2318588
Change-Id: If90ee7e2b777e4c77fdd0ae768d1ececa792ee1b
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/widget/TabHost.java | 5 | ||||
-rw-r--r-- | core/java/android/widget/TabWidget.java | 7 |
2 files changed, 9 insertions, 3 deletions
diff --git a/core/java/android/widget/TabHost.java b/core/java/android/widget/TabHost.java index 31920e7..412f817 100644 --- a/core/java/android/widget/TabHost.java +++ b/core/java/android/widget/TabHost.java @@ -279,6 +279,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); if (!handled && (event.getAction() == KeyEvent.ACTION_DOWN) && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP) + && (mCurrentView != null) && (mCurrentView.isRootNamespace()) && (mCurrentView.hasFocus()) && (mCurrentView.findFocus().focusSearch(View.FOCUS_UP) == null)) { @@ -292,7 +293,9 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); @Override public void dispatchWindowFocusChanged(boolean hasFocus) { - mCurrentView.dispatchWindowFocusChanged(hasFocus); + if (mCurrentView != null){ + mCurrentView.dispatchWindowFocusChanged(hasFocus); + } } public void setCurrentTab(int index) { diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java index 2ba6268..c12d098 100644 --- a/core/java/android/widget/TabWidget.java +++ b/core/java/android/widget/TabWidget.java @@ -183,7 +183,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { @Override public void childDrawableStateChanged(View child) { - if (child == getChildTabViewAt(mSelectedTab)) { + if (getTabCount() > 0 && child == getChildTabViewAt(mSelectedTab)) { // To make sure that the bottom strip is redrawn invalidate(); } @@ -194,6 +194,9 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { public void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); + // Do nothing if there are no tabs. + if (getTabCount() == 0) return; + // If the user specified a custom view for the tab indicators, then // do not draw the bottom strips. if (!mDrawBottomStrips) { @@ -347,7 +350,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { } public void onFocusChange(View v, boolean hasFocus) { - if (v == this && hasFocus) { + if (v == this && hasFocus && getTabCount() > 0) { getChildTabViewAt(mSelectedTab).requestFocus(); return; } |