FileDocCategorySizeDatePackage
AutoCompleteTextView.javaAPI DocAndroid 5.1 API45679Thu Mar 12 22:22:10 GMT 2015android.widget

AutoCompleteTextView

public class AutoCompleteTextView extends EditText implements Filter.FilterListener

An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

The drop down can be dismissed at any time by pressing the back key or, if no item is selected in the drop down, by pressing the enter/dpad center key.

The list of suggestions is obtained from a data adapter and appears only after a given number of characters defined by {@link #getThreshold() the threshold}.

The following code snippet shows how to create a text view which suggests various countries names while the user is typing:

public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}

private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}

See the Text Fields guide.

attr
ref android.R.styleable#AutoCompleteTextView_completionHint
attr
ref android.R.styleable#AutoCompleteTextView_completionThreshold
attr
ref android.R.styleable#AutoCompleteTextView_completionHintView
attr
ref android.R.styleable#AutoCompleteTextView_dropDownSelector
attr
ref android.R.styleable#AutoCompleteTextView_dropDownAnchor
attr
ref android.R.styleable#AutoCompleteTextView_dropDownWidth
attr
ref android.R.styleable#AutoCompleteTextView_dropDownHeight
attr
ref android.R.styleable#ListPopupWindow_dropDownVerticalOffset
attr
ref android.R.styleable#ListPopupWindow_dropDownHorizontalOffset

Fields Summary
static final boolean
DEBUG
static final String
TAG
static final int
EXPAND_MAX
private CharSequence
mHintText
private TextView
mHintView
private int
mHintResource
private ListAdapter
mAdapter
private Filter
mFilter
private int
mThreshold
private ListPopupWindow
mPopup
private int
mDropDownAnchorId
private AdapterView.OnItemClickListener
mItemClickListener
private AdapterView.OnItemSelectedListener
mItemSelectedListener
private boolean
mDropDownDismissedOnCompletion
private int
mLastKeyCode
private boolean
mOpenBefore
private Validator
mValidator
private boolean
mBlockCompletion
private boolean
mPopupCanBeUpdated
private PassThroughClickListener
mPassThroughClickListener
private PopupDataSetObserver
mObserver
Constructors Summary
public AutoCompleteTextView(android.content.Context context)


       
        this(context, null);
    
public AutoCompleteTextView(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, R.attr.autoCompleteTextViewStyle);
    
public AutoCompleteTextView(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)

        this(context, attrs, defStyleAttr, 0);
    
public AutoCompleteTextView(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        super(context, attrs, defStyleAttr, defStyleRes);

        mPopup = new ListPopupWindow(context, attrs, defStyleAttr, defStyleRes);
        mPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);

        final TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.AutoCompleteTextView, defStyleAttr, defStyleRes);

        mThreshold = a.getInt(R.styleable.AutoCompleteTextView_completionThreshold, 2);

        mPopup.setListSelector(a.getDrawable(R.styleable.AutoCompleteTextView_dropDownSelector));

        // Get the anchor's id now, but the view won't be ready, so wait to actually get the
        // view and store it in mDropDownAnchorView lazily in getDropDownAnchorView later.
        // Defaults to NO_ID, in which case the getDropDownAnchorView method will simply return
        // this TextView, as a default anchoring point.
        mDropDownAnchorId = a.getResourceId(R.styleable.AutoCompleteTextView_dropDownAnchor,
                View.NO_ID);
        
        // For dropdown width, the developer can specify a specific width, or MATCH_PARENT
        // (for full screen width) or WRAP_CONTENT (to match the width of the anchored view).
        mPopup.setWidth(a.getLayoutDimension(R.styleable.AutoCompleteTextView_dropDownWidth,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        mPopup.setHeight(a.getLayoutDimension(R.styleable.AutoCompleteTextView_dropDownHeight,
                ViewGroup.LayoutParams.WRAP_CONTENT));

        mHintResource = a.getResourceId(R.styleable.AutoCompleteTextView_completionHintView,
                R.layout.simple_dropdown_hint);
        
        mPopup.setOnItemClickListener(new DropDownItemClickListener());
        setCompletionHint(a.getText(R.styleable.AutoCompleteTextView_completionHint));

        // Always turn on the auto complete input type flag, since it
        // makes no sense to use this widget without it.
        int inputType = getInputType();
        if ((inputType&EditorInfo.TYPE_MASK_CLASS)
                == EditorInfo.TYPE_CLASS_TEXT) {
            inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE;
            setRawInputType(inputType);
        }

        a.recycle();

        setFocusable(true);

        addTextChangedListener(new MyWatcher());
        
        mPassThroughClickListener = new PassThroughClickListener();
        super.setOnClickListener(mPassThroughClickListener);
    
Methods Summary
private voidbuildImeCompletions()

        final ListAdapter adapter = mAdapter;
        if (adapter != null) {
            InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null) {
                final int count = Math.min(adapter.getCount(), 20);
                CompletionInfo[] completions = new CompletionInfo[count];
                int realCount = 0;

                for (int i = 0; i < count; i++) {
                    if (adapter.isEnabled(i)) {
                        Object item = adapter.getItem(i);
                        long id = adapter.getItemId(i);
                        completions[realCount] = new CompletionInfo(id, realCount,
                                convertSelectionToString(item));
                        realCount++;
                    }
                }
                
                if (realCount != count) {
                    CompletionInfo[] tmp = new CompletionInfo[realCount];
                    System.arraycopy(completions, 0, tmp, 0, realCount);
                    completions = tmp;
                }

                imm.displayCompletions(this, completions);
            }
        }
    
public voidclearListSelection()

Clear the list selection. This may only be temporary, as user input will often bring it back.

        mPopup.clearListSelection();
    
protected java.lang.CharSequenceconvertSelectionToString(java.lang.Object selectedItem)

Converts the selected item from the drop down list into a sequence of character that can be used in the edit box.

param
selectedItem the item selected by the user for completion
return
a sequence of characters representing the selected suggestion

        return mFilter.convertResultToString(selectedItem);
    
public voiddismissDropDown()

Closes the drop down if present on screen.

        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm != null) {
            imm.displayCompletions(this, null);
        }
        mPopup.dismiss();
        mPopupCanBeUpdated = false;
    
voiddoAfterTextChanged()

        if (mBlockCompletion) return;

        // if the list was open before the keystroke, but closed afterwards,
        // then something in the keystroke processing (an input filter perhaps)
        // called performCompletion() and we shouldn't do any more processing.
        if (DEBUG) Log.v(TAG, "after text changed: openBefore=" + mOpenBefore
                + " open=" + isPopupShowing());
        if (mOpenBefore && !isPopupShowing()) {
            return;
        }

        // the drop down is shown only when a minimum number of characters
        // was typed in the text view
        if (enoughToFilter()) {
            if (mFilter != null) {
                mPopupCanBeUpdated = true;
                performFiltering(getText(), mLastKeyCode);
            }
        } else {
            // drop down is automatically dismissed when enough characters
            // are deleted from the text view
            if (!mPopup.isDropDownAlwaysVisible()) {
                dismissDropDown();
            }
            if (mFilter != null) {
                mFilter.filter(null);
            }
        }
    
voiddoBeforeTextChanged()

        if (mBlockCompletion) return;

        // when text is changed, inserted or deleted, we attempt to show
        // the drop down
        mOpenBefore = isPopupShowing();
        if (DEBUG) Log.v(TAG, "before text changed: open=" + mOpenBefore);
    
public booleanenoughToFilter()
Returns true if the amount of text in the field meets or exceeds the {@link #getThreshold} requirement. You can override this to impose a different standard for when filtering will be triggered.

        if (DEBUG) Log.v(TAG, "Enough to filter: len=" + getText().length()
                + " threshold=" + mThreshold);
        return getText().length() >= mThreshold;
    
public voidensureImeVisible(boolean visible)
Ensures that the drop down is not obscuring the IME.

param
visible whether the ime should be in front. If false, the ime is pushed to the background.
hide
internal used only here and SearchDialog

        mPopup.setInputMethodMode(visible
                ? ListPopupWindow.INPUT_METHOD_NEEDED : ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
        if (mPopup.isDropDownAlwaysVisible() || (mFilter != null && enoughToFilter())) {
            showDropDown();
        }
    
public ListAdaptergetAdapter()

Returns a filterable list adapter used for auto completion.

return
a data adapter used for auto completion

        return mAdapter;
    
public java.lang.CharSequencegetCompletionHint()
Gets the optional hint text displayed at the bottom of the the matching list.

return
The hint text, if any
see
#setCompletionHint(CharSequence)
attr
ref android.R.styleable#AutoCompleteTextView_completionHint

        return mHintText;
    
public intgetDropDownAnchor()

Returns the id for the view that the auto-complete drop down list is anchored to.

return
the view's id, or {@link View#NO_ID} if none specified
attr
ref android.R.styleable#AutoCompleteTextView_dropDownAnchor

        return mDropDownAnchorId;
    
public intgetDropDownAnimationStyle()

Returns the animation style that is used when the drop-down list appears and disappears

return
the animation style that is used when the drop-down list appears and disappears
hide
Pending API council approval

        return mPopup.getAnimationStyle();
    
public android.graphics.drawable.DrawablegetDropDownBackground()

Gets the background of the auto-complete drop-down list.

return
the background drawable
attr
ref android.R.styleable#PopupWindow_popupBackground

        return mPopup.getBackground();
    
public intgetDropDownHeight()

Returns the current height for the auto-complete drop down list. This can be a fixed height, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill the screen, or {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the height of the drop down's content.

return
the height for the drop down list
attr
ref android.R.styleable#AutoCompleteTextView_dropDownHeight

        return mPopup.getHeight();
    
public intgetDropDownHorizontalOffset()

Gets the horizontal offset used for the auto-complete drop-down list.

return
the horizontal offset
attr
ref android.R.styleable#ListPopupWindow_dropDownHorizontalOffset

        return mPopup.getHorizontalOffset();
    
public intgetDropDownVerticalOffset()

Gets the vertical offset used for the auto-complete drop-down list.

return
the vertical offset
attr
ref android.R.styleable#ListPopupWindow_dropDownVerticalOffset

        return mPopup.getVerticalOffset();
    
public intgetDropDownWidth()

Returns the current width for the auto-complete drop down list. This can be a fixed width, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill the screen, or {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the width of its anchor view.

return
the width for the drop down list
attr
ref android.R.styleable#AutoCompleteTextView_dropDownWidth

        return mPopup.getWidth();
    
protected FiltergetFilter()
Returns the Filter obtained from {@link Filterable#getFilter}, or null if {@link #setAdapter} was not called with a Filterable.

        return mFilter;
    
public AdapterView.OnItemClickListenergetItemClickListener()

Returns the listener that is notified whenever the user clicks an item in the drop down list.

return
the item click listener
deprecated
Use {@link #getOnItemClickListener()} intead

        return mItemClickListener;
    
public AdapterView.OnItemSelectedListenergetItemSelectedListener()

Returns the listener that is notified whenever the user selects an item in the drop down list.

return
the item selected listener
deprecated
Use {@link #getOnItemSelectedListener()} intead

        return mItemSelectedListener;
    
public intgetListSelection()
Get the position of the dropdown view selection, if there is one. Returns {@link ListView#INVALID_POSITION ListView.INVALID_POSITION} if there is no dropdown or if there is no selection.

return
the position of the current selection, if there is one, or {@link ListView#INVALID_POSITION ListView.INVALID_POSITION} if not.
see
ListView#getSelectedItemPosition()

        return mPopup.getSelectedItemPosition();
    
public AdapterView.OnItemClickListenergetOnItemClickListener()

Returns the listener that is notified whenever the user clicks an item in the drop down list.

return
the item click listener

        return mItemClickListener;
    
public AdapterView.OnItemSelectedListenergetOnItemSelectedListener()

Returns the listener that is notified whenever the user selects an item in the drop down list.

return
the item selected listener

        return mItemSelectedListener;
    
public intgetThreshold()

Returns the number of characters the user must type before the drop down list is shown.

return
the minimum number of characters to type to show the drop down
see
#setThreshold(int)
attr
ref android.R.styleable#AutoCompleteTextView_completionThreshold

        return mThreshold;
    
public android.widget.AutoCompleteTextView$ValidatorgetValidator()
Returns the Validator set with {@link #setValidator}, or null if it was not set.

see
#setValidator(android.widget.AutoCompleteTextView.Validator)
see
#performValidation()

        return mValidator;
    
public booleanisDropDownAlwaysVisible()

return
Whether the drop-down is visible as long as there is {@link #enoughToFilter()}
hide
Pending API council approval

        return mPopup.isDropDownAlwaysVisible();
    
public booleanisDropDownDismissedOnCompletion()
Checks whether the drop-down is dismissed when a suggestion is clicked.

hide
Pending API council approval

        return mDropDownDismissedOnCompletion;
    
public booleanisInputMethodNotNeeded()

hide
internal used only here and SearchDialog

        return mPopup.getInputMethodMode() == ListPopupWindow.INPUT_METHOD_NOT_NEEDED;
    
public booleanisPerformingCompletion()
Identifies whether the view is currently performing a text completion, so subclasses can decide whether to respond to text changed events.

        return mBlockCompletion;
    
public booleanisPopupShowing()

Indicates whether the popup menu is showing.

return
true if the popup menu is showing, false otherwise

        return mPopup.isShowing();
    
protected voidonAttachedToWindow()

        super.onAttachedToWindow();
    
private voidonClickImpl()
Private hook into the on click event, dispatched from {@link PassThroughClickListener}

        // If the dropdown is showing, bring the keyboard to the front
        // when the user touches the text field.
        if (isPopupShowing()) {
            ensureImeVisible(true);
        }
    
public voidonCommitCompletion(android.view.inputmethod.CompletionInfo completion)

        if (isPopupShowing()) {
            mPopup.performItemClick(completion.getPosition());
        }
    
protected voidonDetachedFromWindow()

        dismissDropDown();
        super.onDetachedFromWindow();
    
protected voidonDisplayHint(int hint)

        super.onDisplayHint(hint);
        switch (hint) {
            case INVISIBLE:
                if (!mPopup.isDropDownAlwaysVisible()) {
                    dismissDropDown();
                }
                break;
        }
    
public voidonFilterComplete(int count)
{@inheritDoc}

        updateDropDownForFilter(count);
    
protected voidonFocusChanged(boolean focused, int direction, android.graphics.Rect previouslyFocusedRect)

        super.onFocusChanged(focused, direction, previouslyFocusedRect);

        if (mTemporaryDetach) {
            // If we are temporarily in the detach state, then do nothing.
            return;
        }

        // Perform validation if the view is losing focus.
        if (!focused) {
            performValidation();
        }
        if (!focused && !mPopup.isDropDownAlwaysVisible()) {
            dismissDropDown();
        }
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)

        if (mPopup.onKeyDown(keyCode, event)) {
            return true;
        }
        
        if (!isPopupShowing()) {
            switch(keyCode) {
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (event.hasNoModifiers()) {
                    performValidation();
                }
            }
        }

        if (isPopupShowing() && keyCode == KeyEvent.KEYCODE_TAB && event.hasNoModifiers()) {
            return true;
        }

        mLastKeyCode = keyCode;
        boolean handled = super.onKeyDown(keyCode, event);
        mLastKeyCode = KeyEvent.KEYCODE_UNKNOWN;

        if (handled && isPopupShowing()) {
            clearListSelection();
        }

        return handled;
    
public booleanonKeyPreIme(int keyCode, android.view.KeyEvent event)

        if (keyCode == KeyEvent.KEYCODE_BACK && isPopupShowing()
                && !mPopup.isDropDownAlwaysVisible()) {
            // special case for the back key, we do not even try to send it
            // to the drop down list but instead, consume it immediately
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                KeyEvent.DispatcherState state = getKeyDispatcherState();
                if (state != null) {
                    state.startTracking(event, this);
                }
                return true;
            } else if (event.getAction() == KeyEvent.ACTION_UP) {
                KeyEvent.DispatcherState state = getKeyDispatcherState();
                if (state != null) {
                    state.handleUpEvent(event);
                }
                if (event.isTracking() && !event.isCanceled()) {
                    dismissDropDown();
                    return true;
                }
            }
        }
        return super.onKeyPreIme(keyCode, event);
    
public booleanonKeyUp(int keyCode, android.view.KeyEvent event)

        boolean consumed = mPopup.onKeyUp(keyCode, event);
        if (consumed) {
            switch (keyCode) {
            // if the list accepts the key events and the key event
            // was a click, the text view gets the selected item
            // from the drop down as its content
            case KeyEvent.KEYCODE_ENTER:
            case KeyEvent.KEYCODE_DPAD_CENTER:
            case KeyEvent.KEYCODE_TAB:
                if (event.hasNoModifiers()) {
                    performCompletion();
                }
                return true;
            }
        }

        if (isPopupShowing() && keyCode == KeyEvent.KEYCODE_TAB && event.hasNoModifiers()) {
            performCompletion();
            return true;
        }

        return super.onKeyUp(keyCode, event);
    
public voidonWindowFocusChanged(boolean hasWindowFocus)

        super.onWindowFocusChanged(hasWindowFocus);
        if (!hasWindowFocus && !mPopup.isDropDownAlwaysVisible()) {
            dismissDropDown();
        }
    
public voidperformCompletion()

Performs the text completion by converting the selected item from the drop down list into a string, replacing the text box's content with this string and finally dismissing the drop down menu.

        performCompletion(null, -1, -1);
    
private voidperformCompletion(android.view.View selectedView, int position, long id)

        if (isPopupShowing()) {
            Object selectedItem;
            if (position < 0) {
                selectedItem = mPopup.getSelectedItem();
            } else {
                selectedItem = mAdapter.getItem(position);
            }
            if (selectedItem == null) {
                Log.w(TAG, "performCompletion: no selected item");
                return;
            }

            mBlockCompletion = true;
            replaceText(convertSelectionToString(selectedItem));
            mBlockCompletion = false;

            if (mItemClickListener != null) {
                final ListPopupWindow list = mPopup;

                if (selectedView == null || position < 0) {
                    selectedView = list.getSelectedView();
                    position = list.getSelectedItemPosition();
                    id = list.getSelectedItemId();
                }
                mItemClickListener.onItemClick(list.getListView(), selectedView, position, id);
            }
        }

        if (mDropDownDismissedOnCompletion && !mPopup.isDropDownAlwaysVisible()) {
            dismissDropDown();
        }
    
protected voidperformFiltering(java.lang.CharSequence text, int keyCode)

Starts filtering the content of the drop down list. The filtering pattern is the content of the edit box. Subclasses should override this method to filter with a different pattern, for instance a substring of text.

param
text the filtering pattern
param
keyCode the last character inserted in the edit box; beware that this will be null when text is being added through a soft input method.

        mFilter.filter(text, this);
    
public voidperformValidation()
If a validator was set on this view and the current string is not valid, ask the validator to fix it.

see
#getValidator()
see
#setValidator(android.widget.AutoCompleteTextView.Validator)

        if (mValidator == null) return;

        CharSequence text = getText();

        if (!TextUtils.isEmpty(text) && !mValidator.isValid(text)) {
            setText(mValidator.fixText(text));
        }
    
protected voidreplaceText(java.lang.CharSequence text)

Performs the text completion by replacing the current text by the selected item. Subclasses should override this method to avoid replacing the whole content of the edit box.

param
text the selected suggestion in the drop down list

        clearComposingText();

        setText(text);
        // make sure we keep the caret at the end of the text view
        Editable spannable = getText();
        Selection.setSelection(spannable, spannable.length());
    
public voidsetAdapter(T adapter)

Changes the list of data used for auto completion. The provided list must be a filterable list adapter.

The caller is still responsible for managing any resources used by the adapter. Notably, when the AutoCompleteTextView is closed or released, the adapter is not notified. A common case is the use of {@link android.widget.CursorAdapter}, which contains a {@link android.database.Cursor} that must be closed. This can be done automatically (see {@link android.app.Activity#startManagingCursor(android.database.Cursor) startManagingCursor()}), or by manually closing the cursor when the AutoCompleteTextView is dismissed.

param
adapter the adapter holding the auto completion data
see
#getAdapter()
see
android.widget.Filterable
see
android.widget.ListAdapter

        if (mObserver == null) {
            mObserver = new PopupDataSetObserver(this);
        } else if (mAdapter != null) {
            mAdapter.unregisterDataSetObserver(mObserver);
        }
        mAdapter = adapter;
        if (mAdapter != null) {
            //noinspection unchecked
            mFilter = ((Filterable) mAdapter).getFilter();
            adapter.registerDataSetObserver(mObserver);
        } else {
            mFilter = null;
        }

        mPopup.setAdapter(mAdapter);
    
public voidsetCompletionHint(java.lang.CharSequence hint)

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.

param
hint the text to be displayed to the user
see
#getCompletionHint()
attr
ref android.R.styleable#AutoCompleteTextView_completionHint

        mHintText = hint;
        if (hint != null) {
            if (mHintView == null) {
                final TextView hintView = (TextView) LayoutInflater.from(getContext()).inflate(
                        mHintResource, null).findViewById(com.android.internal.R.id.text1);
                hintView.setText(mHintText);
                mHintView = hintView;
                mPopup.setPromptView(hintView);
            } else {
                mHintView.setText(hint);
            }
        } else {
            mPopup.setPromptView(null);
            mHintView = null;
        }
    
public voidsetDropDownAlwaysVisible(boolean dropDownAlwaysVisible)
Sets whether the drop-down should remain visible as long as there is there is {@link #enoughToFilter()}. This is useful if an unknown number of results are expected to show up in the adapter sometime in the future. The drop-down will occupy the entire screen below {@link #getDropDownAnchor} regardless of the size or content of the list. {@link #getDropDownBackground()} will fill any space that is not used by the list.

param
dropDownAlwaysVisible Whether to keep the drop-down visible.
hide
Pending API council approval

        mPopup.setDropDownAlwaysVisible(dropDownAlwaysVisible);
    
public voidsetDropDownAnchor(int id)

Sets the view to which the auto-complete drop down list should anchor. The view corresponding to this id will not be loaded until the next time it is needed to avoid loading a view which is not yet instantiated.

param
id the id to anchor the drop down list view to
attr
ref android.R.styleable#AutoCompleteTextView_dropDownAnchor

        mDropDownAnchorId = id;
        mPopup.setAnchorView(null);
    
public voidsetDropDownAnimationStyle(int animationStyle)

Sets the animation style of the auto-complete drop-down list.

If the drop-down is showing, calling this method will take effect only the next time the drop-down is shown.

param
animationStyle animation style to use when the drop-down appears and disappears. Set to -1 for the default animation, 0 for no animation, or a resource identifier for an explicit animation.
hide
Pending API council approval

        mPopup.setAnimationStyle(animationStyle);
    
public voidsetDropDownBackgroundDrawable(android.graphics.drawable.Drawable d)

Sets the background of the auto-complete drop-down list.

param
d the drawable to set as the background
attr
ref android.R.styleable#PopupWindow_popupBackground

        mPopup.setBackgroundDrawable(d);
    
public voidsetDropDownBackgroundResource(int id)

Sets the background of the auto-complete drop-down list.

param
id the id of the drawable to set as the background
attr
ref android.R.styleable#PopupWindow_popupBackground

        mPopup.setBackgroundDrawable(getContext().getDrawable(id));
    
public voidsetDropDownDismissedOnCompletion(boolean dropDownDismissedOnCompletion)
Sets whether the drop-down is dismissed when a suggestion is clicked. This is true by default.

param
dropDownDismissedOnCompletion Whether to dismiss the drop-down.
hide
Pending API council approval

        mDropDownDismissedOnCompletion = dropDownDismissedOnCompletion;
    
public voidsetDropDownHeight(int height)

Sets the current height for the auto-complete drop down list. This can be a fixed height, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill the screen, or {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the height of the drop down's content.

param
height the height to use
attr
ref android.R.styleable#AutoCompleteTextView_dropDownHeight

        mPopup.setHeight(height);
    
public voidsetDropDownHorizontalOffset(int offset)

Sets the horizontal offset used for the auto-complete drop-down list.

param
offset the horizontal offset
attr
ref android.R.styleable#ListPopupWindow_dropDownHorizontalOffset

        mPopup.setHorizontalOffset(offset);
    
public voidsetDropDownVerticalOffset(int offset)

Sets the vertical offset used for the auto-complete drop-down list.

param
offset the vertical offset
attr
ref android.R.styleable#ListPopupWindow_dropDownVerticalOffset

        mPopup.setVerticalOffset(offset);
    
public voidsetDropDownWidth(int width)

Sets the current width for the auto-complete drop down list. This can be a fixed width, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill the screen, or {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the width of its anchor view.

param
width the width to use
attr
ref android.R.styleable#AutoCompleteTextView_dropDownWidth

        mPopup.setWidth(width);
    
public voidsetForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch)
Forces outside touches to be ignored. Normally if {@link #isDropDownAlwaysVisible()} is false, we allow outside touch to dismiss the dropdown. If this is set to true, then we ignore outside touch even when the drop down is not set to always visible.

hide
used only by SearchDialog

        mPopup.setForceIgnoreOutsideTouch(forceIgnoreOutsideTouch);
    
protected booleansetFrame(int l, int t, int r, int b)

        boolean result = super.setFrame(l, t, r, b);

        if (isPopupShowing()) {
            showDropDown();
        }

        return result;
    
public voidsetListSelection(int position)
Set the position of the dropdown view selection.

param
position The position to move the selector to.

        mPopup.setSelection(position);
    
public voidsetOnClickListener(OnClickListener listener)

        mPassThroughClickListener.mWrapped = listener;
    
public voidsetOnDismissListener(android.widget.AutoCompleteTextView$OnDismissListener dismissListener)
Set a listener that will be invoked whenever the AutoCompleteTextView's list of completions is dismissed.

param
dismissListener Listener to invoke when completions are dismissed

        PopupWindow.OnDismissListener wrappedListener = null;
        if (dismissListener != null) {
            wrappedListener = new PopupWindow.OnDismissListener() {
                @Override public void onDismiss() {
                    dismissListener.onDismiss();
                }
            };
        }
        mPopup.setOnDismissListener(wrappedListener);
    
public voidsetOnItemClickListener(AdapterView.OnItemClickListener l)

Sets the listener that will be notified when the user clicks an item in the drop down list.

param
l the item click listener

        mItemClickListener = l;
    
public voidsetOnItemSelectedListener(AdapterView.OnItemSelectedListener l)

Sets the listener that will be notified when the user selects an item in the drop down list.

param
l the item selected listener

        mItemSelectedListener = l;
    
public voidsetText(java.lang.CharSequence text, boolean filter)
Like {@link #setText(CharSequence)}, except that it can disable filtering.

param
filter If false, no filtering will be performed as a result of this call.

        if (filter) {
            setText(text);
        } else {
            mBlockCompletion = true;
            setText(text);
            mBlockCompletion = false;
        }
    
public voidsetThreshold(int threshold)

Specifies the minimum number of characters the user has to type in the edit box before the drop down list is shown.

When threshold is less than or equals 0, a threshold of 1 is applied.

param
threshold the number of characters to type before the drop down is shown
see
#getThreshold()
attr
ref android.R.styleable#AutoCompleteTextView_completionThreshold

        if (threshold <= 0) {
            threshold = 1;
        }

        mThreshold = threshold;
    
public voidsetValidator(android.widget.AutoCompleteTextView$Validator validator)
Sets the validator used to perform text validation.

param
validator The validator used to validate the text entered in this widget.
see
#getValidator()
see
#performValidation()

        mValidator = validator;
    
public voidshowDropDown()

Displays the drop down on screen.

        buildImeCompletions();

        if (mPopup.getAnchorView() == null) {
            if (mDropDownAnchorId != View.NO_ID) {
                mPopup.setAnchorView(getRootView().findViewById(mDropDownAnchorId));
            } else {
                mPopup.setAnchorView(this);
            }
        }
        if (!isPopupShowing()) {
            // Make sure the list does not obscure the IME when shown for the first time.
            mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
            mPopup.setListItemExpandMax(EXPAND_MAX);
        }
        mPopup.show();
        mPopup.getListView().setOverScrollMode(View.OVER_SCROLL_ALWAYS);
    
public voidshowDropDownAfterLayout()
Issues a runnable to show the dropdown as soon as possible.

hide
internal used only by SearchDialog

        mPopup.postShow();
    
private voidupdateDropDownForFilter(int count)

        // Not attached to window, don't update drop-down
        if (getWindowVisibility() == View.GONE) return;

        /*
         * This checks enoughToFilter() again because filtering requests
         * are asynchronous, so the result may come back after enough text
         * has since been deleted to make it no longer appropriate
         * to filter.
         */

        final boolean dropDownAlwaysVisible = mPopup.isDropDownAlwaysVisible();
        final boolean enoughToFilter = enoughToFilter();
        if ((count > 0 || dropDownAlwaysVisible) && enoughToFilter) {
            if (hasFocus() && hasWindowFocus() && mPopupCanBeUpdated) {
                showDropDown();
            }
        } else if (!dropDownAlwaysVisible && isPopupShowing()) {
            dismissDropDown();
            // When the filter text is changed, the first update from the adapter may show an empty
            // count (when the query is being performed on the network). Future updates when some
            // content has been retrieved should still be able to update the list.
            mPopupCanBeUpdated = true;
        }