使用AutoCompleteTextView控件的步骤

移动开发 Android
AutoCompleteTextView的功能类似于百度或者Google在搜索栏输入信息的时候,弹出的与输入信息接近的提示信息。

AutoCompleteTextView的功能类似于百度或者Google在搜索栏输入信息的时候,弹出的与输入信息接近的提示信息。具体效果是,一个可编辑的文本视图,当用户输入信息后弹出提示。提示列表显示在一个下拉菜单中,用户可以从中选择一项,以完成输入。提示列表是从一个数据适配器获取的数据。

以下是使用的步骤:

第一步:在布局文件中定义控件

  1. <AutoCompleteTextView  
  2.  
  3.         android:id="@+id/actv" 
  4.  
  5.         android:layout_width="fill_parent" 
  6.  
  7.         android:layout_height="wrap_content" 
  8.  
  9. /> 

第二步:在Activity中引用

  1. AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv); 

第三步:创建一个适配器来保存数据

  1. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this
  2.  
  3. ndroid.R.layout.simple_dropdown_item_1line,new String[] {"English""Hebrew""Hindi""German" }); 

第四步:将适配器与AutoCompleteTextView相关联

  1. actv.setAdapter(adapter); 
责任编辑:徐川 来源: OSChina
相关推荐

2009-08-11 15:46:15

C#日历控件

2013-08-26 17:41:43

JavaScriptWindows 8.1

2009-12-30 16:43:47

Silverlight

2009-08-26 17:56:20

C#制做Active控

2011-04-19 17:06:24

bada控件bada

2009-08-03 13:43:02

C#日历控件

2009-08-04 13:23:40

C# 自定义控件dll

2009-07-24 15:35:00

ASP.NET Gri

2009-08-26 17:28:48

C# DateTime

2009-08-07 09:20:26

DataPager数据

2010-12-12 21:01:00

Android控件

2009-08-26 13:36:33

C#打印控件

2009-07-16 13:51:43

2011-11-04 16:34:20

控件Android

2009-08-14 10:42:16

Timer控件的使用C#windows服务

2009-09-08 14:54:40

C# listBox控

2009-01-08 10:20:56

AutoCompletAjaxASP.NET

2009-07-23 16:44:51

AdRotator控件ASP.NET

2009-08-28 16:31:21

C# treeview

2009-02-25 10:55:29

FCKeditor控件JSP
点赞
收藏

51CTO技术栈公众号