IT. Expert System.

Android Reference

AutoCompleteTextView


android.widget

Class AutoCompleteTextView

  • All Implemented Interfaces:
    Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, ViewTreeObserver.OnPreDrawListener, Filter.FilterListener
    Direct Known Subclasses:
    MultiAutoCompleteTextView, SearchView.SearchAutoComplete


    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 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.

    • Constructor Detail

      • AutoCompleteTextView

        public AutoCompleteTextView(Context context)
      • AutoCompleteTextView

        public AutoCompleteTextView(Context context,
                            AttributeSet attrs,
                            int defStyle)
    • Method Detail

      • setOnClickListener

        public void setOnClickListener(View.OnClickListener listener)
        Description copied from class: View
        Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.
        Overrides:
        setOnClickListener in class View
        Parameters:
        listener - The callback that will run
        See Also:
        View.setClickable(boolean)
      • setCompletionHint

        public void setCompletionHint(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.

        Parameters:
        hint - the text to be displayed to the user
        See Also:
        getCompletionHint()
      • getDropDownWidth

        public int getDropDownWidth()

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

        Returns:
        the width for the drop down list
      • setDropDownWidth

        public void setDropDownWidth(int width)

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

        Parameters:
        width - the width to use
      • getDropDownHeight

        public int getDropDownHeight()

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

        Returns:
        the height for the drop down list
      • setDropDownHeight

        public void setDropDownHeight(int height)

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

        Parameters:
        height - the height to use
      • getDropDownAnchor

        public int getDropDownAnchor()

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

        Returns:
        the view's id, or View.NO_ID if none specified
      • setDropDownAnchor

        public void setDropDownAnchor(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.

        Parameters:
        id - the id to anchor the drop down list view to
      • getDropDownBackground

        public Drawable getDropDownBackground()

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

        Returns:
        the background drawable
      • setDropDownBackgroundDrawable

        public void setDropDownBackgroundDrawable(Drawable d)

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

        Parameters:
        d - the drawable to set as the background
      • setDropDownBackgroundResource

        public void setDropDownBackgroundResource(int id)

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

        Parameters:
        id - the id of the drawable to set as the background
      • setDropDownVerticalOffset

        public void setDropDownVerticalOffset(int offset)

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

        Parameters:
        offset - the vertical offset
      • getDropDownVerticalOffset

        public int getDropDownVerticalOffset()

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

        Returns:
        the vertical offset
      • setDropDownHorizontalOffset

        public void setDropDownHorizontalOffset(int offset)

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

        Parameters:
        offset - the horizontal offset
      • getDropDownHorizontalOffset

        public int getDropDownHorizontalOffset()

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

        Returns:
        the horizontal offset
      • setDropDownAnimationStyle

        public void setDropDownAnimationStyle(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.

        Parameters:
        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.
      • getDropDownAnimationStyle

        public int getDropDownAnimationStyle()

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

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

        public boolean isDropDownAlwaysVisible()
        Returns:
        Whether the drop-down is visible as long as there is enoughToFilter()
      • setDropDownAlwaysVisible

        public void setDropDownAlwaysVisible(boolean dropDownAlwaysVisible)
        Sets whether the drop-down should remain visible as long as there is there is 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 getDropDownAnchor() regardless of the size or content of the list. getDropDownBackground() will fill any space that is not used by the list.
        Parameters:
        dropDownAlwaysVisible - Whether to keep the drop-down visible.
      • isDropDownDismissedOnCompletion

        public boolean isDropDownDismissedOnCompletion()
        Checks whether the drop-down is dismissed when a suggestion is clicked.
      • setDropDownDismissedOnCompletion

        public void setDropDownDismissedOnCompletion(boolean dropDownDismissedOnCompletion)
        Sets whether the drop-down is dismissed when a suggestion is clicked. This is true by default.
        Parameters:
        dropDownDismissedOnCompletion - Whether to dismiss the drop-down.
      • getThreshold

        public int getThreshold()

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

        Returns:
        the minimum number of characters to type to show the drop down
        See Also:
        setThreshold(int)
      • setThreshold

        public void setThreshold(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.

        Parameters:
        threshold - the number of characters to type before the drop down is shown
        See Also:
        getThreshold()
      • setOnItemClickListener

        public void setOnItemClickListener(AdapterView.OnItemClickListener l)

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

        Parameters:
        l - the item click listener
      • setOnItemSelectedListener

        public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener l)

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

        Parameters:
        l - the item selected listener
      • getOnItemClickListener

        public AdapterView.OnItemClickListener getOnItemClickListener()

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

        Returns:
        the item click listener
      • getOnItemSelectedListener

        public AdapterView.OnItemSelectedListener getOnItemSelectedListener()

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

        Returns:
        the item selected listener
      • setOnDismissListener

        public void setOnDismissListener(AutoCompleteTextView.OnDismissListener dismissListener)
        Set a listener that will be invoked whenever the AutoCompleteTextView's list of completions is dismissed.
        Parameters:
        dismissListener - Listener to invoke when completions are dismissed
      • getAdapter

        public ListAdapter getAdapter()

        Returns a filterable list adapter used for auto completion.

        Returns:
        a data adapter used for auto completion
      • setAdapter

        public <T extends ListAdapter & Filterable> void setAdapter(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 CursorAdapter, which contains a Cursor that must be closed. This can be done automatically (see startManagingCursor()), or by manually closing the cursor when the AutoCompleteTextView is dismissed.

        Parameters:
        adapter - the adapter holding the auto completion data
        See Also:
        getAdapter(), Filterable, ListAdapter
      • onKeyPreIme

        public boolean onKeyPreIme(int keyCode,
                          KeyEvent event)
        Description copied from class: View
        Handle a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself.
        Overrides:
        onKeyPreIme in class TextView
        Parameters:
        keyCode - The value in event.getKeyCode().
        event - Description of the key event.
        Returns:
        If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.
      • onKeyUp

        public boolean onKeyUp(int keyCode,
                      KeyEvent event)
        Description copied from class: View
        Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER is released.

        Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

        Specified by:
        onKeyUp in interface KeyEvent.Callback
        Overrides:
        onKeyUp in class TextView
        Parameters:
        keyCode - A key code that represents the button pressed, from KeyEvent.
        event - The KeyEvent object that defines the button action.
        Returns:
        If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.
      • onKeyDown

        public boolean onKeyDown(int keyCode,
                        KeyEvent event)
        Description copied from class: View
        Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER is released, if the view is enabled and clickable.

        Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

        Specified by:
        onKeyDown in interface KeyEvent.Callback
        Overrides:
        onKeyDown in class TextView
        Parameters:
        keyCode - A key code that represents the button pressed, from KeyEvent.
        event - The KeyEvent object that defines the button action.
        Returns:
        If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.
      • enoughToFilter

        public boolean enoughToFilter()
        Returns true if the amount of text in the field meets or exceeds the getThreshold() requirement. You can override this to impose a different standard for when filtering will be triggered.
      • isPopupShowing

        public boolean isPopupShowing()

        Indicates whether the popup menu is showing.

        Returns:
        true if the popup menu is showing, false otherwise
      • convertSelectionToString

        protected CharSequence convertSelectionToString(Object selectedItem)

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

        Parameters:
        selectedItem - the item selected by the user for completion
        Returns:
        a sequence of characters representing the selected suggestion
      • clearListSelection

        public void clearListSelection()

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

      • setListSelection

        public void setListSelection(int position)
        Set the position of the dropdown view selection.
        Parameters:
        position - The position to move the selector to.
      • performFiltering

        protected void performFiltering(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.

        Parameters:
        text - the filtering pattern
        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.
      • performCompletion

        public void performCompletion()

        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.

      • onCommitCompletion

        public void onCommitCompletion(CompletionInfo completion)
        Description copied from class: TextView
        Called by the framework in response to a text completion from the current input method, provided by it calling InputConnection.commitCompletion(). The default implementation does nothing; text views that are supporting auto-completion should override this to do their desired behavior.
        Overrides:
        onCommitCompletion in class TextView
        Parameters:
        completion - The auto complete text the user has selected.
      • isPerformingCompletion

        public boolean isPerformingCompletion()
        Identifies whether the view is currently performing a text completion, so subclasses can decide whether to respond to text changed events.
      • setText

        public void setText(CharSequence text,
                   boolean filter)
        Like TextView.setText(CharSequence), except that it can disable filtering.
        Parameters:
        filter - If false, no filtering will be performed as a result of this call.
      • replaceText

        protected void replaceText(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.

        Parameters:
        text - the selected suggestion in the drop down list
      • onFilterComplete

        public void onFilterComplete(int count)

        Notifies the end of a filtering operation.

        Specified by:
        onFilterComplete in interface Filter.FilterListener
        Parameters:
        count - the number of values computed by the filter
      • onWindowFocusChanged

        public void onWindowFocusChanged(boolean hasWindowFocus)
        Description copied from class: View
        Called when the window containing this view gains or loses focus. Note that this is separate from view focus: to receive key events, both your view and its window must have focus. If a window is displayed on top of yours that takes input focus, then your own window will lose focus but the view focus will remain unchanged.
        Overrides:
        onWindowFocusChanged in class TextView
        Parameters:
        hasWindowFocus - True if the window containing this view now has focus, false otherwise.
      • onDisplayHint

        protected void onDisplayHint(int hint)
        Description copied from class: View
        Gives this view a hint about whether is displayed or not. For instance, when a View moves out of the screen, it might receives a display hint indicating the view is not displayed. Applications should not rely on this hint as there is no guarantee that they will receive one.
        Overrides:
        onDisplayHint in class View
        Parameters:
        hint - A hint about whether or not this view is displayed: View.VISIBLE or View.INVISIBLE.
      • onFocusChanged

        protected void onFocusChanged(boolean focused,
                          int direction,
                          Rect previouslyFocusedRect)
        Description copied from class: View
        Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.
        Overrides:
        onFocusChanged in class TextView
        Parameters:
        focused - True if the View has focus; false otherwise.
        direction - The direction focus has moved when requestFocus() is called to give this view focus. Values are View.FOCUS_UP, View.FOCUS_DOWN, View.FOCUS_LEFT, View.FOCUS_RIGHT, View.FOCUS_FORWARD, or View.FOCUS_BACKWARD. It may not always apply, in which case use the default.
        previouslyFocusedRect - The rectangle, in this view's coordinate system, of the previously focused view. If applicable, this will be passed in as finer grained information about where the focus is coming from (in addition to direction). Will be null otherwise.
      • onDetachedFromWindow

        protected void onDetachedFromWindow()
        Description copied from class: View
        This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
        Overrides:
        onDetachedFromWindow in class TextView
        See Also:
        View.onAttachedToWindow()
      • dismissDropDown

        public void dismissDropDown()

        Closes the drop down if present on screen.

      • setFrame

        protected boolean setFrame(int l,
                       int t,
                       int r,
                       int b)
        Description copied from class: View
        Assign a size and position to this view. This is called from layout.
        Overrides:
        setFrame in class TextView
        Parameters:
        l - Left position, relative to parent
        t - Top position, relative to parent
        r - Right position, relative to parent
        b - Bottom position, relative to parent
        Returns:
        true if the new size and position are different than the previous ones
      • showDropDownAfterLayout

        public void showDropDownAfterLayout()
        Issues a runnable to show the dropdown as soon as possible.
      • ensureImeVisible

        public void ensureImeVisible(boolean visible)
        Ensures that the drop down is not obscuring the IME.
        Parameters:
        visible - whether the ime should be in front. If false, the ime is pushed to the background.
      • isInputMethodNotNeeded

        public boolean isInputMethodNotNeeded()
      • showDropDown

        public void showDropDown()

        Displays the drop down on screen.

      • setForceIgnoreOutsideTouch

        public void setForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch)
        Forces outside touches to be ignored. Normally if 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.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 128 / 158736323. Delta: 0.07430 с