Android-使用代码创建AutoCompleteTextView(完全没有xml)
创始人
2024-08-19 21:30:07
0
  1. 先创建AutoCompleteTextView的实例:

AutoCompleteTextView autoCompleteTextView = new AutoCompleteTextView(context);

  1. 设置AutoCompleteTextView的布局参数:

autoCompleteTextView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

  1. 给AutoCompleteTextView设置适配器,这里使用了一个简单的字符串数组适配器:

String[] suggestions = {"Apple", "Banana", "Cherry", "Coconut"}; ArrayAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_dropdown_item_1line, suggestions); autoCompleteTextView.setAdapter(adapter);

  1. 最后将AutoCompleteTextView添加到父布局中:

parentLayout.addView(autoCompleteTextView);

完整示例代码:

LinearLayout parentLayout = findViewById(R.id.parent_layout);

AutoCompleteTextView autoCompleteTextView = new AutoCompleteTextView(context); autoCompleteTextView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

String[] suggestions = {"Apple", "Banana", "Cherry", "Coconut"}; ArrayAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_dropdown_item_1line, suggestions); autoCompleteTextView.setAdapter(adapter);

parentLayout.addView(autoCompleteTextView);

相关内容

热门资讯

推荐几款新版!哈糖大菠萝可以开... 推荐几款新版!哈糖大菠萝可以开挂吗,约局吧是否有挂,必胜教程(有挂神器);支持多人共享记分板与复盘,...
玩家必看科普!uupoker有... 您好,wepoker模拟器哪个这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很...
重要通知!pokemmo修改器... 此外,数据分析德州(pokemmo修改器手机版)辅助神器app还具备辅助透视行为开挂功能,通过对客户...
推荐一款!aapoker真的假... 推荐一款!aapoker真的假的,aapoker透视脚本,线上教程(有挂软件);最新版2024是一款...
今日百科!wepoker私人局... 今日百科!wepoker私人局开挂视频,wepoker辅助器如何使用,黑科技教程(有挂技巧)准备好在...
我来教教你!wpk作弊,hhp... 这是一款非常优秀的hhpoker作弊码怎么用 ia辅助检测软件,能够让你了解到hhpoker作弊码怎...
科技新动态!黑侠破解wepok... 1、科技新动态!黑侠破解wepoker,aapoker透视脚本入口,教你教程(有挂辅助);详细教程。...
专业讨论!wepoker挂,h... 专业讨论!wepoker挂,hhpoker是正规的吗,解说技巧(有挂辅助)准备好在hhpoker是正...
技术分享!hhpoker有没有... 技术分享!hhpoker有没有作弊辅助,wepoker免费脚本咨询,规律教程(有挂攻略);大神普及一...
指导大家!wepoker透视辅... 指导大家!wepoker透视辅助下载,wepoker游戏的安装教程,规律教程(有挂技巧);最新版20...