【Android学习笔记】AutoCompleteTextView(数组在代码中)

注:本笔记英文原版就在你的电脑中:X:/Program Files/Android/android-sdk-windows/docs/resources/tutorials/views/hello-autocomplete.html(X即你安装SDK的盘符。)

 

它的属性可见:X:/Program Files/Android/android-sdk-windows/docs/reference/android/widget/AutoCompleteTextView.html


下载本示例源码

 

AutoCompleteTextView是一个根据数组适配器中已有的文本进行自动提示功能的TextView。

在本次学习笔记中,我们来创建一个AutoCompleteTextView,目的是为了自动提示国家的名字。

1.在eclipse中新建一个名为AutoTextViewSample的Android项目;

2.创建一个名为list_item.xml的文件存放于res/layout/中,代码如下:

这个文件中加入一个简单的TextView,它将用于显示提示文本。

 

3.打开res/layout/main.xml,并插入以为代码:

 

其中的TextView是用于介绍AutoCompleteTextView。

 

4.打开AutoTextViewSample.java,并插入以下代码:

After the content view is set to the main.xml layout, the AutoCompleteTextView widget is captured from the layout with findViewById(int). A new ArrayAdapter is then initialized to bind the list_item.xml layout to each list item in the COUNTRIES string array (defined in the next step). Finally, setAdapter() is called to associate the ArrayAdapter with the AutoCompleteTextView widget so that the string array will populate the list of suggestions.

 

5.同样在AutoTextViewSample.java中定义一个类,如下:

这些就是自动提示的建议文本,将以下拉列表的形式体现。

 

 

现在来看看效果:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值