summaryrefslogtreecommitdiff
path: root/core/java/android/widget/AutoCompleteTextView.java
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2010-03-16 13:49:31 -0700
committerRomain Guy <romainguy@android.com>2010-03-16 13:49:31 -0700
commit6a67810228d02e75446d55c4c353275c87e9e769 (patch)
tree6d223f780de79d7e5922f0515fb60d122f12e4a8 /core/java/android/widget/AutoCompleteTextView.java
parent52c6c108d371dd2ad0fdea1c7e4762abbbd3b0fc (diff)
Resize AutoCompleteTextView's dropdown when the list content changes.
Bug #2517711 Change-Id: Ibd4a9458d517063483712a60fb6d6b63311bbd0c
Diffstat (limited to 'core/java/android/widget/AutoCompleteTextView.java')
-rw-r--r--core/java/android/widget/AutoCompleteTextView.java90
1 files changed, 31 insertions, 59 deletions
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index 1156e15ddff9..9537ba0fa07e 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -18,6 +18,7 @@ package android.widget;
import android.content.Context;
import android.content.res.TypedArray;
+import android.database.DataSetObserver;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.Editable;
@@ -129,10 +130,11 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
private boolean mBlockCompletion;
- private AutoCompleteTextView.ListSelectorHider mHideSelector;
+ private ListSelectorHider mHideSelector;
private Runnable mShowDropDownRunnable;
- private AutoCompleteTextView.PassThroughClickListener mPassThroughClickListener;
+ private PassThroughClickListener mPassThroughClickListener;
+ private PopupDataSetObserver mObserver;
public AutoCompleteTextView(Context context) {
this(context, null);
@@ -218,14 +220,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
}
/**
- * Sets this to be single line; a separate method so
- * MultiAutoCompleteTextView can skip this.
- */
- /* package */ void finishInit() {
- setSingleLine();
- }
-
- /**
* <p>Sets the optional hint text that is displayed at the bottom of the
* the matching list. This can be used as a cue to the user on how to
* best use the list, or to provide extra information.</p>
@@ -448,7 +442,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
public boolean isDropDownDismissedOnCompletion() {
return mDropDownDismissedOnCompletion;
}
-
+
/**
* Sets whether the drop-down is dismissed when a suggestion is clicked. This is
* true by default.
@@ -590,10 +584,16 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
* @see android.widget.ListAdapter
*/
public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
+ if (mObserver == null) {
+ mObserver = new PopupDataSetObserver();
+ } else if (mAdapter != null) {
+ mAdapter.unregisterDataSetObserver(mObserver);
+ }
mAdapter = adapter;
if (mAdapter != null) {
//noinspection unchecked
mFilter = ((Filterable) mAdapter).getFilter();
+ adapter.registerDataSetObserver(mObserver);
} else {
mFilter = null;
}
@@ -866,16 +866,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
return ListView.INVALID_POSITION;
}
-
- /**
- * @hide
- * @return {@link android.widget.ListView#getChildCount()} of the drop down if it is showing,
- * otherwise 0.
- */
- protected int getDropDownChildCount() {
- return mDropDownList == null ? 0 : mDropDownList.getChildCount();
- }
-
/**
* <p>Starts filtering the content of the drop down list. The filtering
* pattern is the content of the edit box. Subclasses should override this
@@ -976,25 +966,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
mBlockCompletion = false;
}
}
-
- /**
- * Like {@link #setTextKeepState(CharSequence)}, except that it can disable filtering.
- *
- * @param filter If <code>false</code>, no filtering will be performed
- * as a result of this call.
- *
- * @hide Pending API council approval.
- */
- public void setTextKeepState(CharSequence text, boolean filter) {
- if (filter) {
- setTextKeepState(text);
- } else {
- mBlockCompletion = true;
- setTextKeepState(text);
- mBlockCompletion = false;
- }
- }
-
+
/**
* <p>Performs the text completion by replacing the current text by the
* selected item. Subclasses should override this method to avoid replacing
@@ -1523,24 +1495,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
return view;
}
- /**
- * <p>Returns the top padding of the currently selected view.</p>
- *
- * @return the height of the top padding for the selection
- */
- public int getSelectionPaddingTop() {
- return mSelectionTopPadding;
- }
-
- /**
- * <p>Returns the bottom padding of the currently selected view.</p>
- *
- * @return the height of the bottom padding for the selection
- */
- public int getSelectionPaddingBottom() {
- return mSelectionBottomPadding;
- }
-
@Override
public boolean isInTouchMode() {
// WARNING: Please read the comment where mListSelectionHidden is declared
@@ -1638,5 +1592,23 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
if (mWrapped != null) mWrapped.onClick(v);
}
}
-
+
+ private class PopupDataSetObserver extends DataSetObserver {
+ @Override
+ public void onChanged() {
+ if (isPopupShowing()) {
+ // This will resize the popup to fit the new adapter's content
+ showDropDown();
+ }
+ }
+
+ @Override
+ public void onInvalidated() {
+ if (!mDropDownAlwaysVisible) {
+ // There's no data to display so make sure we're not showing
+ // the drop down and its list
+ dismissDropDown();
+ }
+ }
+ }
}