在android中我们可以使用AutoCompleteTextView来实现自动提示功能。
我们将需要进行提示的数据放入ArrayAdapter中,然后用AutoCompleteTextView的setAdapter方法,就可以让AutoCompleteTextView具有自动完成提示的功能了.
autocomplete.xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<AutoCompleteTextView android:id="@+id/autoComplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</AutoCompleteTextView>
</LinearLayout>
java代码
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
/**
* 自动完成文本
* @author daist
* @date 2010-9-25
*/
public class AutoCompleteActivity extends Activity {
private static final String[] COUNTRIES = {"China","Russia","Germany",
"Ukraine","Belarus","USA","China1","China2","USA1"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.autocomplete);
//创建一个ArrayAdapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,COUNTRIES);
//获取AutoCompleteTextView对象
AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete);
//将AutoCompleteTextView与ArrayAdapter进行绑定
autoComplete.setAdapter(adapter);
//设置AutoCompleteTextView输入1个字符就进行提示
autoComplete.setThreshold(1);
}
}
运行效果
- 大小: 14 KB
分享到:
相关推荐
android 具有自动提示功能的菜单AutoCompleteTextView与数组
NULL 博文链接:https://sraining.iteye.com/blog/726710
本Demo展示了Android项目中AutoCompleteTextView以及MultiAutoCompleteTextView的简单使用,对其进行属性设置,以及数据填充。
Android AutoCompleteTextView自动提示输入。我博客网址: http://blog.csdn.net/qq_16064871。我写了很多博客都是有源码的,请多多关注。
主要介绍了Android自动提示控件AutoCompleteTextView的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
值得一提的是,AutoCompleteTextView和MultiAutoCompleteTextView这两种自动提示框有什么区别呢,可以由上图看得出来,后者可以将字符串分割开来之后仍然能够自动提示,这是前者做不到的。教程地址:...
主要为大家详细介绍了Android用户输入自动提示控件AutoCompleteTextView的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文主要介绍了Android自动补全提示输入AutoCompleteTextView、 MultiAutoCompleteTextView,具有一定的参考作用,下面跟着小编一起来看下吧
自动编辑文本框(AutoCompleteTextView)继承自EditText,能够接受用户的输入编辑,但是有这自己的特色功能:输入一定的字符以后会弹出下拉列表提示供用户选择,用户选择之后会自动填充文本框。这项功能正如浏览器的...
可以自动补齐邮箱后缀的控件,很适合邮箱的注册于邮箱登录
我们使用控件AutoCompleteTextView 自动提示时,有时需要设置BaseAdapter,设置BaseAdapter时,需要实现Filterable,手动进行筛选。 常用属性 布局只设置了至少输入一个字符显示提示 <AutoCompleteTextView ...
主要介绍了Android仿百度谷歌搜索自动提示框AutoCompleteTextView简单应用,结合实例形式分析了AutoCompleteTextView Widget使用步骤与相关操作技巧,需要的朋友可以参考下
自动完成文本框(AutoCompleteTextView),可根据用户输入的内容,匹配指定的数据源,以列表的形式显示数据源中所有符合要求的数据,以供用户选择,减少用户的输入内容,方便用户使用。例如常用购物平台的搜索框、...
AutoCompleteTextView自动提示输入文字信息,结合listview使用
自动提示文本框(AutoCompleteTextView)可以加强用户体验,缩短用户的输入时间(百度的搜索框就是这个效果)。 先给大家展示下效果图,如果大家感觉还不错,请参考实现代码: 最后一张获取文本框里面的值(其实就跟...
Android开发(30)--AutoCompleteTextView和----MultiAutoCompleteTextView自动提示输入内容