您的位置:首页 > 其它

输入内容自动完成文本框(AutoCompleteTextView )

2011-12-19 19:29 766 查看
AutoCompleteTextView和EditText组件类似,都可以输入文本。
但AutoCompleteTextView组件可以和一个字符串数组或List对象
绑定,当用户输入两个及以上字符时,系统将在
AutoCompleteTextView组件下方列出字符串数组中所有以输入
字符开头的字符串,这一点和www.google.com的搜索框非常相似,
当输入某一个要查找的字符串时,google搜索框就会列出以这个
字符串开头的最热门的搜索字符串列表。
<AutoCompleteTextView
android:layout_width="fill_parent“ android:layout_height="wrap_content“
<!– completionThreshold 指定至少输入几个字符后才会出现自动提示功能 à
android:completionThreshold="1“
android:id="@+id/name" />
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentView(R.layout.main);
String[] names = {"老张", "老方", "老毕", "李明" , "李丽", "陈江", "abc", "acc"};
AutoCompleteTextView nameText = (AutoCompleteTextView)this.findViewById(R.id.name);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, names);

nameText.setAdapter(adapter);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: