Android开发之AutoCompleteTextView :自动提供可选择内容
- AutoCompleteTextView继承了EditText,可编辑。根据输入的字符自动出现一个下拉列表供选择想要的完整字符串并将它填充到编辑框中,然后列表会消失。
- 当要删除编辑框中的内容时,每当删除一个字符,如果剩下的字符串有匹配内容也会出现列表,可供选择新的字符串。

代码如下:
<AutoCompleteTextView
android:id="@+id/ACTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
AutoCompleteTextView ACTV= (AutoCompleteTextView)findViewById(R.id.ACTV);
String [] str= {"one","two","three","four","five","six","seven","eight","nine","forth"};
ArrayAdapter madapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,str);
ACTV.setAdapter(madapter);