Android实现自动文本框提示功能
更新时间:2017年10月20日 14:02:48 作者:konekou
这篇文章主要为大家详细介绍了Android实现自动文本框提示功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Android实现自动文本框提示的具体代码,供大家参考,具体内容如下

activity_main.xml布局
<LinearLayout 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:orientation="vertical" >
<!--
默认输2个字符才能有提示
completionThreshold表示只输入1个字符后,就有提示
requestFocus表示界面展开时焦点直接在第二个文本框
-->
<AutoCompleteTextView
android:id="@+id/myTextView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1" />
<MultiAutoCompleteTextView
android:id="@+id/myTextView02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1">
<requestFocus />
</MultiAutoCompleteTextView>
</LinearLayout>
代码实现
public class MainActivity extends Activity {
private AutoCompleteTextView myTextView01;
private MultiAutoCompleteTextView myTextView02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myTextView01 = (AutoCompleteTextView) findViewById(R.id.myTextView01);
myTextView02 = (MultiAutoCompleteTextView) findViewById(R.id.myTextView02);
String[] str={"xiaohe","xiaowang","xiaoli","zhanghe","zhangmin","zhaojun","lihe","daming"};
/*
* 创建适配器
* 参数一:上下文
* 参数二:提示下位框的样式,不喜欢可以换android.R.layout.*
* 参数三:下拉框中备选的内容
*/
ArrayAdapter<String> adapter=new ArrayAdapter<String>(
this,
android.R.layout.simple_dropdown_item_1line,
str);
//将Adapter设置到AutoCompleteTextView中
myTextView01.setAdapter(adapter);
myTextView02.setAdapter(adapter);
//以","作为分隔符
myTextView02.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- Android自动编辑文本框(AutoCompleteTextView)使用方法详解
- Android AutoCompleteTextView自动提示文本框实例代码
- Android自动文本框输入识别提示功能代码
- Android中EditText和AutoCompleteTextView设置文字选中颜色方法
- Android中AutoCompleteTextView与MultiAutoCompleteTextView的用法
- Android AutoCompleteTextView控件使用实例
- 基于Android中的 AutoCompleteTextView实现自动填充
- 实例讲解Android中的AutoCompleteTextView自动补全组件
- Android AutoCompleteTextView连接数据库自动提示的方法(附demo源码下载)
- Android高级组件AutoCompleteTextView自动完成文本框使用详解
相关文章
解决android studio android monitor打不开的问题
下面小编就为大家分享一篇解决android studio android monitor打不开的问题,具有很的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-01-01
详解Android使用Html.fromHtml需要注意的地方
本篇文章主要介绍了详解Android使用Html.fromHtml需要注意的地方,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-07-07
Eclipse工程转为兼容Android Studio模式的方法步骤图文详解
这篇文章主要介绍了Eclipse工程转为兼容Android Studio模式的方法步骤,本文图文并茂给大家介绍的非常详细,需要的朋友可以参考下2017-12-12


最新评论