我个人认为它是为能够更准确的搜索而设计的,如果只输入a,那它的搜索范围太大,导致没办法显示,底下就有匹配 aa,ab,ac...这样自动搜索没有意义。
AutoCompleteTextView是一个可以完成自动提示填充内容的TextView,比TextView多的功能就是提示功能,效果如下:
AutoCompleteTextView 输入aa后会提示aaa,这是提前设置的main.xml内的AutoCompleteTextView定义 <AutoCompleteTextView android:id="@+id/autotext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/> java文件里设置提示的内容: AutoCompleteTextView autotext = (AutoCompleteTextView)findViewById(R.id.autotext);
String[] auto={"aaa","bcde","cderef"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, auto) ;
autotext.setAdapter(adapter);类似的View还有MultiAutoCompleteTextView,多一行代码 multiauto.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());据说能增加提示项,但如何实现呢,我做了结果和 AutoCompleteTextView 完全一样,这行代码不加也没错误,但不给提示。
AutoCompleteTextView是一个可以完成自动提示填充内容的TextView,比TextView多的功能就是提示功能,效果如下:
AutoCompleteTextView 输入aa后会提示aaa,这是提前设置的main.xml内的AutoCompleteTextView定义 <AutoCompleteTextView android:id="@+id/autotext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/> java文件里设置提示的内容: AutoCompleteTextView autotext = (AutoCompleteTextView)findViewById(R.id.autotext);
String[] auto={"aaa","bcde","cderef"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, auto) ;
autotext.setAdapter(adapter);类似的View还有MultiAutoCompleteTextView,多一行代码 multiauto.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());据说能增加提示项,但如何实现呢,我做了结果和 AutoCompleteTextView 完全一样,这行代码不加也没错误,但不给提示。
这个方法就是设置你输入几个才会给出提示,系统默认的是
public void setThreshold(int threshold) {
if (threshold <= 0) {
threshold = 1;
} mThreshold = threshold;
}
相信楼主一看就明白了, 为啥是出俩个字母才给提示了。