自动提示文本框(autoCompleteTextVIEw)可以加强用户体验,缩短用户的输入时间(百度的搜索框就是这个效果)。
相信大家都熟悉自动识别提示吧,在我们的生活中随处可见,今天就让我为大家简单介绍一下它是如何设计的。
所谓自动识别输入即是根据用户输入的已有信息,为用户提示可能的值,方便用户完成输入。在AndroID设备上这种功能分为:autoCompleteTextVIEw和MultiautoCompleteTextVIEw,前者为单个的自动识别,类似与搜索引擎的输入框提示;后者为多个值自动识别,类似与发邮件时的邮箱输入框。那它们俩到底如何使用呢?下面就让我们一起学习一下吧。
首先是布局文件:
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:paddingBottom="@dimen/activity_vertical_margin"androID:paddingleft="@dimen/activity_horizontal_margin"androID:paddingRight="@dimen/activity_horizontal_margin"androID:paddingtop="@dimen/activity_vertical_margin"tools:context=".Activityfive" ><autoCompleteTextVIEw androID:ID="@+ID/acTextVIEw"androID:layout_wIDth="match_parent"androID:layout_height="wrap_content"androID:hint="请输入姓名:"androID:textcolor="#000"androID:maxLength="10"/><MultiautoCompleteTextVIEwandroID:ID="@+ID/macTextVIEw"androID:layout_below="@ID/acTextVIEw"androID:layout_wIDth="match_parent"androID:layout_height="wrap_content"androID:hint="请输入城市:"androID:textcolor="#000"androID:maxLength="20"/></relativeLayout>
注:androID:hint属性为提示文字内容,当如何输入框获得焦点后自动消失
下面是我们的Action:
import androID.app.Activity;import androID.os.Bundle;import androID.Widget.ArrayAdapter;import androID.Widget.autoCompleteTextVIEw;import androID.Widget.MultiautoCompleteTextVIEw;public class Activityfive extends Activity{private autoCompleteTextVIEw acTextVIEw;private MultiautoCompleteTextVIEw macTextVIEw;private String [] arr = {"abc","abx","abo","bdc","bdf"};private String [] brr = {"ab北京","ab南京","ab东京","bb莫斯科","bb英国","bb美国"};@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {// Todo auto-generated method stubsuper.onCreate(savedInstanceState);setContentVIEw(R.layout.activity_five);acTextVIEw = (autoCompleteTextVIEw) findVIEwByID(R.ID.acTextVIEw);macTextVIEw = (MultiautoCompleteTextVIEw) findVIEwByID(R.ID.macTextVIEw);ArrayAdapter<String> arrAdapt = new ArrayAdapter<String>(this,androID.R.layout.simple_dropdown_item_1line,arr); acTextVIEw.setAdapter(arrAdapt);ArrayAdapter<String> brrAdapt = new ArrayAdapter<String>(this,brr);macTextVIEw.setAdapter(brrAdapt);macTextVIEw.setThreshold(1);//设置输入多少个字符开始自动匹配macTextVIEw.setTokenizer(new MultiautoCompleteTextVIEw.CommaTokenizer());//设置分隔符}}
以上所述是小编给大家介绍的AndroID自动文本框输入识别提示功能代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
总结以上是内存溢出为你收集整理的Android自动文本框输入识别提示功能代码全部内容,希望文章能够帮你解决Android自动文本框输入识别提示功能代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)