`
mapdigit
  • 浏览: 241903 次
文章分类
社区版块
存档分类
最新评论

Android ApiDemos示例解析(99):Views->Auto Complete->1. Screen Top

 
阅读更多

本例 1. Screen Top ,2. Screen Bottom , 3. Scroll 都是介绍AutoCompleteTextView 的用法,不同的是AutoCompleteTextView 中Layout 位置不同,可以看到 AutoCompleteTextView 根据其位置的不同自动为提示对话框会选择合适的位置在屏幕上显示。

在使用Google搜索时,Google 搜索项会随着用户输入自动给出相关提示,类AutoCompleteTextView 提供了类似的功能,在AutoCompleteTextView输入时,随着用户的输入,AutoCompleteTextView会显示一个提示列表可以供用户选择,用户可以使用Back 键随时取消这个提示框。

提示框的内容来自于一个Data Adapter ,并可以通过设定 threshold 给出用户输入超过几个字符后才出现提示框。

本例为提示框添加国家名称的提示:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
 android.R.layout.simple_dropdown_item_1line,
 COUNTRIES);
AutoCompleteTextView textView
 = (AutoCompleteTextView) findViewById(R.id.edit);
textView.setAdapter(adapter);

...
static final String[] COUNTRIES = new String[] {
 "Afghanistan", "Albania", "Algeria", "American Samoa",
 "Andorra", "Angola", "Anguilla", "Antarctica",
 "Antigua and Barbuda", "Argentina" ..

本例的AutoCompleteTextView 位置在屏幕的上部,可以看看提示框显示的位置:


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics