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);

相关内容

热门资讯

必看攻略!德普之星有辅助软件吗... 必看攻略!德普之星有辅助软件吗,aapoker破解侠是真的吗,安装教程(有挂攻略)1、很好的工具软件...
科普常识!wepoker私人局... 科普常识!wepoker私人局透视教程,wpk插件,科技教程(有挂攻略)是一款可以让一直输的玩家,快...
一分钟了解!wepoker辅助... 一分钟了解!wepoker辅助是真的假的,pokemmo脚本辅助器,安装教程(有挂软件)是一款可以让...
玩家必看科普!来玩德州破解器,... 玩家必看科普!来玩德州破解器,德州局透视脚本,AI教程(有挂神器);致您一封信;亲爱德州局透视脚本玩...
专业讨论!wepoker透视脚... 1、专业讨论!wepoker透视脚本免费下载,拱趴大菠萝机器人,普及教程(有挂攻略)(UU poke...
玩家必看科普!wepoker新... 玩家必看科普!wepoker新号好一点吗,epoker透视底牌,爆料教程(有挂教程);1分钟了解详细...
一秒答解!智星德州可以透视吗,... 一秒答解!智星德州可以透视吗,we poker插件,细节方法(有挂技巧);实战中需综合运用上述技巧,...
玩家必看教程!hhpoker免... 玩家必看教程!hhpoker免费透视脚本,poker辅助器免费安装,wpk教程(有挂透明);玩家必备...
重大通报!pokemmo免费脚... 重大通报!pokemmo免费脚本,德州hhpoker是真的吗,力荐教程(有挂方法)是一款可以让一直输...
实测教程!约局吧如何查看是否有... 实测教程!约局吧如何查看是否有挂,智星菠萝可以辅助吗,wepoke教程(有挂软件)准备好在约局吧如何...