Android怎么实现自动文本框提示功能
发布时间:-04-16 12:28:30
来源:亿速云
阅读:92
作者:小新
这篇文章主要介绍Android怎么实现自动文本框提示功能,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
具体内容如下
activity_main.xml布局
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/myTextView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"/>
android:id="@+id/myTextView02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1">
代码实现publicclassMainActivityextendsActivity{
privateAutoCompleteTextViewmyTextView01;
privateMultiAutoCompleteTextViewmyTextView02;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
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.*
*参数三:下拉框中备选的内容
*/
ArrayAdapteradapter=newArrayAdapter(
this,
android.R.layout.simple_dropdown_item_1line,
str);
//将Adapter设置到AutoCompleteTextView中
myTextView01.setAdapter(adapter);
myTextView02.setAdapter(adapter);
//以","作为分隔符
myTextView02.setTokenizer(maTokenizer());
}
}
以上是“Android怎么实现自动文本框提示功能”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!