MultiAutoCompleteTextViewpublic class MultiAutoCompleteTextView extends AutoCompleteTextView An editable text view, extending {@link AutoCompleteTextView}, that
can show completion suggestions for the substring of the text where
the user is typing instead of necessarily for the entire thing.
You must provide a {@link Tokenizer} to distinguish the
various substrings.
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 savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.autocomplete_7);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.edit);
textView.setAdapter(adapter);
textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
} |
Fields Summary |
---|
private Tokenizer | mTokenizer |
Constructors Summary |
---|
public MultiAutoCompleteTextView(android.content.Context context)
this(context, null);
| public MultiAutoCompleteTextView(android.content.Context context, android.util.AttributeSet attrs)
this(context, attrs, com.android.internal.R.attr.autoCompleteTextViewStyle);
| public MultiAutoCompleteTextView(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)
this(context, attrs, defStyleAttr, 0);
| public MultiAutoCompleteTextView(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)
super(context, attrs, defStyleAttr, defStyleRes);
|
Methods Summary |
---|
public boolean | enoughToFilter()Instead of filtering whenever the total length of the text
exceeds the threshhold, this subclass filters only when the
length of the range from
{@link Tokenizer#findTokenStart} to {@link #getSelectionEnd}
meets or exceeds {@link #getThreshold}.
Editable text = getText();
int end = getSelectionEnd();
if (end < 0 || mTokenizer == null) {
return false;
}
int start = mTokenizer.findTokenStart(text, end);
if (end - start >= getThreshold()) {
return true;
} else {
return false;
}
| void | finishInit()
| public void | onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
super.onInitializeAccessibilityEvent(event);
event.setClassName(MultiAutoCompleteTextView.class.getName());
| public void | onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(MultiAutoCompleteTextView.class.getName());
| protected void | performFiltering(java.lang.CharSequence text, int start, int end, int keyCode)Starts filtering the content of the drop down list. The filtering
pattern is the specified range of text from the edit box. Subclasses may
override this method to filter with a different pattern, for
instance a smaller substring of text .
getFilter().filter(text.subSequence(start, end), this);
| protected void | performFiltering(java.lang.CharSequence text, int keyCode)Instead of filtering on the entire contents of the edit box,
this subclass method filters on the range from
{@link Tokenizer#findTokenStart} to {@link #getSelectionEnd}
if the length of that range meets or exceeds {@link #getThreshold}.
if (enoughToFilter()) {
int end = getSelectionEnd();
int start = mTokenizer.findTokenStart(text, end);
performFiltering(text, start, end, keyCode);
} else {
dismissDropDown();
Filter f = getFilter();
if (f != null) {
f.filter(null);
}
}
| public void | performValidation()Instead of validating the entire text, this subclass method validates
each token of the text individually. Empty tokens are removed.
Validator v = getValidator();
if (v == null || mTokenizer == null) {
return;
}
Editable e = getText();
int i = getText().length();
while (i > 0) {
int start = mTokenizer.findTokenStart(e, i);
int end = mTokenizer.findTokenEnd(e, start);
CharSequence sub = e.subSequence(start, end);
if (TextUtils.isEmpty(sub)) {
e.replace(start, i, "");
} else if (!v.isValid(sub)) {
e.replace(start, i,
mTokenizer.terminateToken(v.fixText(sub)));
}
i = start;
}
| protected void | replaceText(java.lang.CharSequence text)Performs the text completion by replacing the range from
{@link Tokenizer#findTokenStart} to {@link #getSelectionEnd} by the
the result of passing text through
{@link Tokenizer#terminateToken}.
In addition, the replaced region will be marked as an AutoText
substition so that if the user immediately presses DEL, the
completion will be undone.
Subclasses may override this method to do some different
insertion of the content into the edit box.
clearComposingText();
int end = getSelectionEnd();
int start = mTokenizer.findTokenStart(getText(), end);
Editable editable = getText();
String original = TextUtils.substring(editable, start, end);
QwertyKeyListener.markAsReplaced(editable, start, end, original);
editable.replace(start, end, mTokenizer.terminateToken(text));
| public void | setTokenizer(android.widget.MultiAutoCompleteTextView$Tokenizer t)Sets the Tokenizer that will be used to determine the relevant
range of the text where the user is typing.
mTokenizer = t;
|
|