|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.view.View
android.widget.TextView
android.widget.EditText
android.widget.AutoCompleteTextView
public class AutoCompleteTextView
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 adapter = new ArrayAdapter(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"
};
}
| Nested Class Summary | |
|---|---|
static interface |
AutoCompleteTextView.Validator
This interface is used to make sure that the text entered in this TextView complies to a certain format. |
| Nested classes/interfaces inherited from class android.widget.TextView |
|---|
TextView.BufferType, TextView.SavedState |
| Nested classes/interfaces inherited from class android.view.View |
|---|
View.BaseSavedState, View.MeasureSpec, View.OnClickListener, View.OnCreateContextMenuListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnLongClickListener, View.OnTouchListener |
| Field Summary |
|---|
| Constructor Summary | |
|---|---|
AutoCompleteTextView(Context context)
|
|
AutoCompleteTextView(Context context,
AttributeSet attrs)
|
|
AutoCompleteTextView(Context context,
AttributeSet attrs,
int defStyle)
|
|
| Method Summary | ||
|---|---|---|
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. |
|
void |
dismissDropDown()
Closes the drop down if present on screen. |
|
boolean |
enoughToFilter()
Returns true if the amount of text in the field meets
or exceeds the getThreshold() requirement. |
|
(package private) void |
finishInit()
Sets this to be single line; a separate method so MultiAutoCompleteTextView can skip this. |
|
ListAdapter |
getAdapter()
Returns a filterable list adapter used for auto completion. |
|
protected Filter |
getFilter()
Returns the Filter obtained from Filterable.getFilter(),
or null if setAdapter(T) was not called with
a Filterable. |
|
AdapterView.OnItemClickListener |
getItemClickListener()
Returns the listener that is notified whenever the user clicks an item in the drop down list. |
|
AdapterView.OnItemSelectedListener |
getItemSelectedListener()
Returns the listener that is notified whenever the user selects an item in the drop down list. |
|
int |
getThreshold()
Returns the number of characters the user must type before the drop down list is shown. |
|
AutoCompleteTextView.Validator |
getValidator()
Returns the Validator set with setValidator(android.widget.AutoCompleteTextView.Validator),
or null if it was not set. |
|
boolean |
isPopupShowing()
Indicates whether the popup menu is showing. |
|
void |
onFilterComplete(int count)
Notifies the end of a filtering operation. |
|
protected void |
onFocusChanged(boolean focused,
int direction,
Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes. |
|
boolean |
onKeyDown(int keyCode,
KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyMultiple(): perform press of the view
when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER
is released, if the view is enabled and clickable. |
|
boolean |
onKeyUp(int keyCode,
KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyMultiple(): perform clicking of the view
when KeyEvent.KEYCODE_DPAD_CENTER or
KeyEvent.KEYCODE_ENTER is released. |
|
protected void |
onTextChanged(CharSequence text,
int start,
int before,
int after)
This method is called when the text is changed, in case any subclasses would like to know. |
|
void |
onWindowFocusChanged(boolean hasWindowFocus)
Called when the window containing this view gains or loses focus. |
|
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. |
|
protected void |
performFiltering(CharSequence text,
int keyCode)
Starts filtering the content of the drop down list. |
|
void |
performValidation()
If a validator was set on this view and the current string is not valid, ask the validator to fix it. |
|
protected void |
replaceText(CharSequence text)
Performs the text completion by replacing the current text by the selected item. |
|
|
setAdapter(T adapter)
Changes the list of data used for auto completion. |
|
void |
setCompletionHint(CharSequence hint)
Sets the optional hint text that is displayed at the bottom of the the matching list. |
|
protected boolean |
setFrame(int l,
int t,
int r,
int b)
Assign a size and position to this view. |
|
void |
setOnItemClickListener(AdapterView.OnItemClickListener l)
Sets the listener that will be notified when the user clicks an item in the drop down list. |
|
void |
setOnItemSelectedListener(AdapterView.OnItemSelectedListener l)
Sets the listener that will be notified when the user selects an item in the drop down list. |
|
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. |
|
void |
setValidator(AutoCompleteTextView.Validator validator)
|
|
void |
showDropDown()
Displays the drop down on screen. |
|
| Methods inherited from class android.widget.EditText |
|---|
extendSelection, getDefaultEditable, getDefaultMovementMethod, getText, selectAll, setSelection, setSelection, setText |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AutoCompleteTextView(Context context)
public AutoCompleteTextView(Context context,
AttributeSet attrs)
public AutoCompleteTextView(Context context,
AttributeSet attrs,
int defStyle)
| Method Detail |
|---|
void finishInit()
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.
hint - the text to be displayed to the userpublic int getThreshold()
Returns the number of characters the user must type before the drop down list is shown.
setThreshold(int)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.
threshold - the number of characters to type before the drop down
is showngetThreshold()public void setOnItemClickListener(AdapterView.OnItemClickListener l)
Sets the listener that will be notified when the user clicks an item in the drop down list.
l - the item click listenerpublic void setOnItemSelectedListener(AdapterView.OnItemSelectedListener l)
Sets the listener that will be notified when the user selects an item in the drop down list.
l - the item selected listenerpublic AdapterView.OnItemClickListener getItemClickListener()
Returns the listener that is notified whenever the user clicks an item in the drop down list.
public AdapterView.OnItemSelectedListener getItemSelectedListener()
Returns the listener that is notified whenever the user selects an item in the drop down list.
public ListAdapter getAdapter()
Returns a filterable list adapter used for auto completion.
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.
adapter - the adapter holding the auto completion datagetAdapter(),
Filterable,
ListAdapter
public boolean onKeyUp(int keyCode,
KeyEvent event)
ViewKeyEvent.Callback.onKeyMultiple(): perform clicking of the view
when KeyEvent.KEYCODE_DPAD_CENTER or
KeyEvent.KEYCODE_ENTER is released.
onKeyUp in interface KeyEvent.CallbackonKeyUp in class TextViewkeyCode - A key code that represents the button pressed, from
KeyEvent.event - The KeyEvent object that defines the button action.
public boolean onKeyDown(int keyCode,
KeyEvent event)
ViewKeyEvent.Callback.onKeyMultiple(): perform press of the view
when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER
is released, if the view is enabled and clickable.
onKeyDown in interface KeyEvent.CallbackonKeyDown in class TextViewkeyCode - A key code that represents the button pressed, from
KeyEvent.event - The KeyEvent object that defines the button action.
public boolean enoughToFilter()
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.
protected void onTextChanged(CharSequence text,
int start,
int before,
int after)
TextView
onTextChanged in class TextViewtext - The text the TextView is displaying.start - The offset of the start of the range of the text
that was modified.before - The offset of the former end of the range of the
text that was modified. If text was simply inserted,
this will be the same as start.
If text was replaced with new text or deleted, the
length of the old text was before-start.after - The offset of the end of the range of the text
that was modified. If text was simply deleted,
this will be the same as start.
If text was replaced with new text or inserted,
the length of the new text is after-start.public boolean isPopupShowing()
Indicates whether the popup menu is showing.
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.
selectedItem - the item selected by the user for completion
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.
text - the filtering patternkeyCode - the last character inserted in the edit boxpublic 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.
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.
text - the selected suggestion in the drop down listpublic void onFilterComplete(int count)
Filter.FilterListenerNotifies the end of a filtering operation.
onFilterComplete in interface Filter.FilterListenercount - the number of values computed by the filterpublic void onWindowFocusChanged(boolean hasWindowFocus)
View
onWindowFocusChanged in class TextViewhasWindowFocus - True if the window containing this view now has
focus, false otherwise.
protected void onFocusChanged(boolean focused,
int direction,
Rect previouslyFocusedRect)
View
onFocusChanged in class TextViewfocused - 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 or
View.FOCUS_RIGHT. 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.public void dismissDropDown()
Closes the drop down if present on screen.
protected boolean setFrame(int l,
int t,
int r,
int b)
View
setFrame in class TextViewl - Left position, relative to parentt - Top position, relative to parentr - Right position, relative to parentb - Bottom position, relative to parent
public void showDropDown()
Displays the drop down on screen.
public void setValidator(AutoCompleteTextView.Validator validator)
public AutoCompleteTextView.Validator getValidator()
setValidator(android.widget.AutoCompleteTextView.Validator),
or null if it was not set.
public void performValidation()
protected Filter getFilter()
Filterable.getFilter(),
or null if setAdapter(T) was not called with
a Filterable.
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||