diff options
| author | 2010-01-19 16:56:05 -0800 | |
|---|---|---|
| committer | 2010-01-19 16:56:05 -0800 | |
| commit | 73beee234b4758318a4a795822e53ffb847fa10e (patch) | |
| tree | d1860c2bd835095d86000d50e756bf54f72b3d30 | |
| parent | 3c79a4abf816f58956831d551b858642139a082b (diff) | |
Measure AutoCompleteTextView's dropdown to have enough room for all items.
Bug #2363514
| -rw-r--r-- | core/java/android/widget/AutoCompleteTextView.java | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index bb9a672e84af..d53a4426683a 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -1331,20 +1331,26 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe final int maxHeight = mPopup.getMaxAvailableHeight( getDropDownAnchorView(), mDropDownVerticalOffset, ignoreBottomDecorations); + // getMaxAvailableHeight() subtracts the padding, so we put it back, + // to get the available height for the whole window + int padding = 0; + Drawable background = mPopup.getBackground(); + if (background != null) { + background.getPadding(mTempRect); + padding = mTempRect.top + mTempRect.bottom; + } + if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) { - // getMaxAvailableHeight() subtracts the padding, so we put it back, - // to get the available height for the whole window - int padding = 0; - Drawable background = mPopup.getBackground(); - if (background != null) { - background.getPadding(mTempRect); - padding = mTempRect.top + mTempRect.bottom; - } return maxHeight + padding; } - return mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED, - 0, ListView.NO_POSITION, maxHeight - otherHeights, 2) + otherHeights; + final int listContent = mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED, + 0, ListView.NO_POSITION, maxHeight - otherHeights, 2); + // add padding only if the list has items in it, that way we don't show + // the popup if it is not needed + if (listContent > 0) otherHeights += padding; + + return listContent + otherHeights; } private View getHintView(Context context) { |