1作用:
AutoCompleteTextView和EditText一样都可以输入文本。但它可以和适配器绑定,当用户输入两个及以上字符时,系统将根据适配器提供的内容,进行文本的自动匹配提示。
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" }; }
属性名 | 关联方法 | 描述 |
---|---|---|
android:completionHint | setCompletionHint(CharSequence) | 定义了提示中显示下拉菜单。 |
android:completionHintView | 定义了视图中显示下拉菜单中。 | |
android:completionThreshold | setThreshold(int) | 定义了用户必须输入的字符的数量完成前建议显示在一个下拉菜单。 |
android:dropDownAnchor | setDropDownAnchor(int) | 锚的自动完成下拉。 |
android:dropDownHeight | setDropDownHeight(int) | 指定的基本高度下拉。 |
android:dropDownHorizontalOffset | 的像素数量的下降应该抵消水平。 | |
android:dropDownSelector | 下拉列表中选择。 | |
android:dropDownVerticalOffset | 的像素数量的下降应该垂直偏移。 | |
android:dropDownWidth | setDropDownWidth(int) | 指定的基本宽度下拉。 |
android:popupBackground | setDropDownBackgroundResource(int) | |
公共方法
public boolean enoughToFilter ()
此方法并不是检验什么时候文本的总长度超过了预定的值,而是在仅当从函数findTokenStart()到getSelectionEnd()函数得到的文本长度为0或者超过了预定值的时候才起作用。(译者注:当文本长度超过阈值时过滤)
public void performValidation ()
此子类方法并不是用来确定整个文本的有效性,而是用来确定文本中的单个符号的有效性。空标记将被移除。
public void setTokenizer (MultiAutoCompleteTextView.Tokenizer t)
设置用来决定用户正在输入文本的范围的分词组件。
受保护方法
protected void performFiltering (CharSequence text, int keyCode)
此方法并不过滤整个编辑框的内容,只是过滤从函数findTokenStart() 到函数getSelectionEnd()获得的长度为0或者超过了预定的值的文本内容。
参数
text 指定过滤模式
keyCode 插入到编辑框中的最后一个字符;当字符(文本)是通过软键盘输入的时候,小心此字符的值可能为NULL。
protected void performFiltering (CharSequence text, int start, int end, int keyCode)
启动对下拉式列表内容的过滤。过滤模式为编辑框中指定的范围。子类可覆盖此方法,以便于采用一个不同的模式。
protected void replaceText (CharSequence text)
通过替换从函数findTokenStart() 到函数 getSelectionEnd()得到的文本文本范围以及传递给函数terminateToken()的文版返回的结果来实现文本的输入。另外,文本的替换区域将会被标记为自动文本区,这样如果用户直接按DEL键,执行过程就会停止。子类可覆盖此方法来实现许多不同的文本插入工作。
参数
text 下拉列表里的选中项
自己做的模糊查询支持A-Z排序:http://download.youkuaiyun.com/detail/u011080584/6521427