本文实例讲述了android autocompletetextview控件基本用法。分享给大家供大家参考,具体如下:
当输入部分内容之后会有相关的建议,类似于百度提示信息
1、在布局文件中声明一个autocompletetextview
<autocompletetextview android:id="@+id/autocomplete_country" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginleft="5dp" />
2、定义一个提示条目的样式,在layout目录下建立list_item.xml文件
<?xml version="1.0" encoding="utf-8"?> <textview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textsize="16sp" android:textcolor="#000"> </textview>
3、它需要使用arrayadapter来提供数据
public void setautocompletetextview(){ autocompletetextview = (autocompletetextview)findviewbyid(r.id.autocomplete_country); //countries是一个数组,autocompletetextview会将数组内容和用户输入的匹配,然后再显示出来提示用户 //r.layout.list_item显示的是提示信息显示的内容的样式 arrayadapter<string> arrayadapter = new arrayadapter<string>(this, r.layout.list_item, countries); autocompletetextview.setadapter(arrayadapter); }
备注:countries是一个数组类型
4、将autocompletetextview和arrayadapter联系起来
更多关于android相关内容感兴趣的读者可查看本站专题:《android文件操作技巧汇总》、《android编程开发之sd卡操作方法汇总》、《android开发入门与进阶教程》、《android资源操作技巧汇总》、《android视图view技巧总结》及《android控件用法总结》
希望本文所述对大家android程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
网友评论