这篇文章主要介绍Android怎么实现自动文本框提示功能,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!具体内容如下activity_main.xml布局<LinearLayout xmlns:andr
这篇文章主要介绍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"}; 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怎么实现自动文本框提示功能”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网精选频道!
--结束END--
本文标题: Android怎么实现自动文本框提示功能
本文链接: https://www.lsjlt.com/news/220602.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0