FileDocCategorySizeDatePackage
AutoCompleteTextView.javaAPI DocAndroid 1.5 API43194Wed May 06 22:41:56 BST 2009android.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"
};
}
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

Fields Summary
static final boolean
DEBUG
static final String
TAG
private static final int
HINT_VIEW_ID
private CharSequence
mHintText
private int
mHintResource
private ListAdapter
mAdapter
private Filter
mFilter
private int
mThreshold
private PopupWindow
mPopup
private DropDownListView
mDropDownList
private int
mDropDownVerticalOffset
private int
mDropDownHorizontalOffset
private int
mDropDownAnchorId
private android.view.View
mDropDownAnchorView
private int
mDropDownWidth
private android.graphics.drawable.Drawable
mDropDownListHighlight
private AdapterView.OnItemClickListener
mItemClickListener
private AdapterView.OnItemSelectedListener
mItemSelectedListener
private final DropDownItemClickListener
mDropDownItemClickListener
private int
mLastKeyCode
private boolean
mOpenBefore
private Validator
mValidator
private boolean
mBlockCompletion
private ListSelectorHider
mHideSelector
private int
mAttachCount
Constructors Summary
public AutoCompleteTextView(android.content.Context context)


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

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

        super(context, attrs, defStyle);

        mPopup = new PopupWindow(context, attrs,
                com.android.internal.R.attr.autoCompleteTextViewStyle);

        TypedArray a =
            context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.AutoCompleteTextView, defStyle, 0);

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

        mHintText = a.getText(R.styleable.AutoCompleteTextView_completionHint);

        mDropDownListHighlight = a.getDrawable(
                R.styleable.AutoCompleteTextView_dropDownSelector);
        mDropDownVerticalOffset = (int)
                a.getDimension(R.styleable.AutoCompleteTextView_dropDownVerticalOffset, 0.0f);
        mDropDownHorizontalOffset = (int)
                a.getDimension(R.styleable.AutoCompleteTextView_dropDownHorizontalOffset, 0.0f);
        
        // 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 FILL_PARENT
        // (for full screen width) or WRAP_CONTENT (to match the width of the anchored view).
        mDropDownWidth = a.getLayoutDimension(R.styleable.AutoCompleteTextView_dropDownWidth,
                ViewGroup.LayoutParams.WRAP_CONTENT);

        mHintResource = a.getResourceId(R.styleable.AutoCompleteTextView_completionHintView,
                R.layout.simple_dropdown_hint);

        // 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());
    
Methods Summary
private intbuildDropDown()

Builds the popup window's content and returns the height the popup should have. Returns -1 when the content already exists.

return
the content's height or -1 if content already exists

        ViewGroup dropDownView;
        int otherHeights = 0;

        if (mAdapter != null) {
            InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null) {
                int N = mAdapter.getCount();
                if (N > 20) N = 20;
                CompletionInfo[] completions = new CompletionInfo[N];
                for (int i = 0; i < N; i++) {
                    Object item = mAdapter.getItem(i);
                    long id = mAdapter.getItemId(i);
                    completions[i] = new CompletionInfo(id, i,
                            convertSelectionToString(item));
                }
                imm.displayCompletions(this, completions);
            }
        }

        if (mDropDownList == null) {
            Context context = getContext();

            mHideSelector = new ListSelectorHider();

            mDropDownList = new DropDownListView(context);
            mDropDownList.setSelector(mDropDownListHighlight);
            mDropDownList.setAdapter(mAdapter);
            mDropDownList.setVerticalFadingEdgeEnabled(true);
            mDropDownList.setOnItemClickListener(mDropDownItemClickListener);
            mDropDownList.setFocusable(true);
            mDropDownList.setFocusableInTouchMode(true);

            if (mItemSelectedListener != null) {
                mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
            }

            dropDownView = mDropDownList;

            View hintView = getHintView(context);
            if (hintView != null) {
                // if an hint has been specified, we accomodate more space for it and
                // add a text view in the drop down menu, at the bottom of the list
                LinearLayout hintContainer = new LinearLayout(context);
                hintContainer.setOrientation(LinearLayout.VERTICAL);

                LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.FILL_PARENT, 0, 1.0f
                );
                hintContainer.addView(dropDownView, hintParams);
                hintContainer.addView(hintView);

                // measure the hint's height to find how much more vertical space
                // we need to add to the drop down's height
                int widthSpec = MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST);
                int heightSpec = MeasureSpec.UNSPECIFIED;
                hintView.measure(widthSpec, heightSpec);

                hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams();
                otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin
                        + hintParams.bottomMargin;

                dropDownView = hintContainer;
            }

            mPopup.setContentView(dropDownView);
        } else {
            dropDownView = (ViewGroup) mPopup.getContentView();
            final View view = dropDownView.findViewById(HINT_VIEW_ID);
            if (view != null) {
                LinearLayout.LayoutParams hintParams =
                        (LinearLayout.LayoutParams) view.getLayoutParams();
                otherHeights = view.getMeasuredHeight() + hintParams.topMargin
                        + hintParams.bottomMargin;
            }
        }

        // Max height available on the screen for a popup anchored to us
        final int maxHeight = mPopup.getMaxAvailableHeight(this, mDropDownVerticalOffset);
        //otherHeights += dropDownView.getPaddingTop() + dropDownView.getPaddingBottom();

        return mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED,
                0, ListView.NO_POSITION, maxHeight - otherHeights, 2) + otherHeights;
    
public voidclearListSelection()

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

        if (mDropDownList != null) {
            mDropDownList.hideSelector();
            mDropDownList.requestLayout();
        }
    
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();
        mPopup.setContentView(null);
        mDropDownList = null;
    
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) {
                performFiltering(getText(), mLastKeyCode);
            }
        } else {
            // drop down is automatically dismissed when enough characters
            // are deleted from the text view
            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;
    
voidfinishInit()
Sets this to be single line; a separate method so MultiAutoCompleteTextView can skip this.

        setSingleLine();
    
public ListAdaptergetAdapter()

Returns a filterable list adapter used for auto completion.

return
a data adapter used for auto completion

        return mAdapter;
    
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

        return mDropDownAnchorId;
    
private android.view.ViewgetDropDownAnchorView()

Used for lazy instantiation of the anchor view from the id we have. If the value of the id is NO_ID or we can't find a view for the given id, we return this TextView as the default anchoring point.

        if (mDropDownAnchorView == null && mDropDownAnchorId != View.NO_ID) {
            mDropDownAnchorView = getRootView().findViewById(mDropDownAnchorId);
        }
        return mDropDownAnchorView == null ? this : mDropDownAnchorView;
    
public intgetDropDownWidth()

Returns the current width for the auto-complete drop down list. This can be a fixed width, or {@link ViewGroup.LayoutParams#FILL_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

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

        return mFilter;
    
private android.view.ViewgetHintView(android.content.Context context)

        if (mHintText != null && mHintText.length() > 0) {
            final TextView hintView = (TextView) LayoutInflater.from(context).inflate(
                    mHintResource, null).findViewById(com.android.internal.R.id.text1);
            hintView.setText(mHintText);
            hintView.setId(HINT_VIEW_ID);
            return hintView;
        } else {
            return null;
        }
    
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()

        if (mPopup.isShowing() && (mDropDownList != null)) {
            return mDropDownList.getSelectedItemPosition();
        }
        return ListView.INVALID_POSITION;
    
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)

        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 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();
        mAttachCount++;
    
public voidonCommitCompletion(android.view.inputmethod.CompletionInfo completion)

        if (isPopupShowing()) {
            mBlockCompletion = true;
            replaceText(completion.getText());
            mBlockCompletion = false;

            if (mItemClickListener != null) {
                final DropDownListView list = mDropDownList;
                // Note that we don't have a View here, so we will need to
                // supply null.  Hopefully no existing apps crash...
                mItemClickListener.onItemClick(list, null, completion.getPosition(),
                        completion.getId());
            }
        }
    
protected voidonDetachedFromWindow()

        dismissDropDown();
        mAttachCount--;
        super.onDetachedFromWindow();
    
public voidonFilterComplete(int count)

        if (mAttachCount <= 0) 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.
         */

        if (count > 0 && enoughToFilter()) {
            if (hasFocus() && hasWindowFocus()) {
                showDropDown();
            }
        } else {
            dismissDropDown();
        }
    
protected voidonFocusChanged(boolean focused, int direction, android.graphics.Rect previouslyFocusedRect)

        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        performValidation();
        if (!focused) {
            dismissDropDown();
        }
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)

        // when the drop down is shown, we drive it directly
        if (isPopupShowing()) {
            // the key events are forwarded to the list in the drop down view
            // note that ListView handles space but we don't want that to happen
            // also if selection is not currently in the drop down, then don't
            // let center or enter presses go there since that would cause it
            // to select one of its items
            if (keyCode != KeyEvent.KEYCODE_SPACE
                    && (mDropDownList.getSelectedItemPosition() >= 0
                            || (keyCode != KeyEvent.KEYCODE_ENTER
                                    && keyCode != KeyEvent.KEYCODE_DPAD_CENTER))) {
                int curIndex = mDropDownList.getSelectedItemPosition();
                boolean consumed;
                final boolean below = !mPopup.isAboveAnchor();
                if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= 0) ||
                        (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >=
                        mDropDownList.getAdapter().getCount() - 1)) {
                    // When the selection is at the top, we block the key
                    // event to prevent focus from moving.
                    mDropDownList.hideSelector();
                    mDropDownList.requestLayout();
                    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
                    mPopup.update();
                    return true;
                }
                consumed = mDropDownList.onKeyDown(keyCode, event);
                if (DEBUG) Log.v(TAG, "Key down: code=" + keyCode + " list consumed="
                        + consumed);
                if (consumed) {
                    // If it handled the key event, then the user is
                    // navigating in the list, so we should put it in front.
                    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
                    // Here's a little trick we need to do to make sure that
                    // the list view is actually showing its focus indicator,
                    // by ensuring it has focus and getting its window out
                    // of touch mode.
                    mDropDownList.requestFocusFromTouch();
                    mPopup.update();

                    switch (keyCode) {
                        // avoid passing the focus from the text view to the
                        // next component
                        case KeyEvent.KEYCODE_ENTER:
                        case KeyEvent.KEYCODE_DPAD_CENTER:
                        case KeyEvent.KEYCODE_DPAD_DOWN:
                        case KeyEvent.KEYCODE_DPAD_UP:
                            return true;
                    }
                } else {
                    if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                        // when the selection is at the bottom, we block the
                        // event to avoid going to the next focusable widget
                        Adapter adapter = mDropDownList.getAdapter();
                        if (adapter != null && curIndex == adapter.getCount() - 1) {
                            return true;
                        }
                    } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex == 0) {
                        return true;
                    }
                }
            }
        } else {
            switch(keyCode) {
            case KeyEvent.KEYCODE_DPAD_DOWN:
                performValidation();
            }
        }

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

        if (handled && isPopupShowing() && mDropDownList != null) {
            clearListSelection();
        }

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

        if (isPopupShowing()) {
            // 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 (keyCode == KeyEvent.KEYCODE_BACK) {
                dismissDropDown();
                return true;
            }
        }
        return super.onKeyPreIme(keyCode, event);
    
public booleanonKeyUp(int keyCode, android.view.KeyEvent event)

        if (isPopupShowing() && mDropDownList.getSelectedItemPosition() >= 0) {
            boolean consumed = mDropDownList.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:
                        performCompletion();
                        return true;
                }
            }
        }
        return super.onKeyUp(keyCode, event);
    
public voidonWindowFocusChanged(boolean hasWindowFocus)

        super.onWindowFocusChanged(hasWindowFocus);
        performValidation();
        if (!hasWindowFocus) {
            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 = mDropDownList.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 DropDownListView list = mDropDownList;

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

        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

        setText(text);
        // make sure we keep the caret at the end of the text view
        Editable spannable = getText();
        Selection.setSelection(spannable, spannable.length());
    
public voidresetListAndClearViews()
We're changing the adapter and its views so really, really clear everything out

hide
- for SearchDialog only

        if (mDropDownList != null) {
            mDropDownList.resetListAndClearViews();
        }
    
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

        mAdapter = adapter;
        if (mAdapter != null) {
            //noinspection unchecked
            mFilter = ((Filterable) mAdapter).getFilter();
        } else {
            mFilter = null;
        }

        if (mDropDownList != null) {
            mDropDownList.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
attr
ref android.R.styleable#AutoCompleteTextView_completionHint

        mHintText = hint;
    
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

        mDropDownAnchorId = id;
        mDropDownAnchorView = null;
    
public voidsetDropDownHorizontalOffset(int horizontalOffset)
Set the horizontal offset with respect to {@link #setDropDownAnchor(int)}

hide
pending API council review

        mDropDownHorizontalOffset = horizontalOffset;
    
public voidsetDropDownVerticalOffset(int verticalOffset)
Set the vertical offset with respect to {@link #setDropDownAnchor(int)}

hide
pending API council review

        mDropDownVerticalOffset = verticalOffset;
    
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#FILL_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

        mDropDownWidth = width;
    
protected booleansetFrame(int l, int t, int r, int b)

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

        if (mPopup.isShowing()) {
            mPopup.update(this, r - l, -1);
        }

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

param
position The position to move the selector to.

        if (mPopup.isShowing() && (mDropDownList != null)) {
            mDropDownList.setSelection(position);
            // ListView.setSelection() will call requestLayout()
        }
    
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 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.

        int height = buildDropDown();
        if (mPopup.isShowing()) {
            int widthSpec;
            if (mDropDownWidth == ViewGroup.LayoutParams.FILL_PARENT) {
                // The call to PopupWindow's update method below can accept -1 for any
                // value you do not want to update.
                widthSpec = -1;
            } else if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) {
                widthSpec = getDropDownAnchorView().getWidth();
            } else {
                widthSpec = mDropDownWidth;
            }
            mPopup.update(getDropDownAnchorView(), mDropDownHorizontalOffset,
                    mDropDownVerticalOffset, widthSpec, height);
        } else {
            if (mDropDownWidth == ViewGroup.LayoutParams.FILL_PARENT) {
                mPopup.setWindowLayoutMode(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
            } else {
                mPopup.setWindowLayoutMode(0, ViewGroup.LayoutParams.WRAP_CONTENT);
                if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) {
                    mPopup.setWidth(getDropDownAnchorView().getWidth());
                } else {
                    mPopup.setWidth(mDropDownWidth);
                }
            }
            mPopup.setHeight(height);
            mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
            mPopup.setOutsideTouchable(true);
            mPopup.setTouchInterceptor(new PopupTouchIntercepter());
            mPopup.showAsDropDown(getDropDownAnchorView(),
                    mDropDownHorizontalOffset, mDropDownVerticalOffset);
            mDropDownList.setSelection(ListView.INVALID_POSITION);
            mDropDownList.hideSelector();
            mDropDownList.requestFocus();
            post(mHideSelector);
        }