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

相关内容

热门资讯

透视有挂!wepoker底牌透... 透视有挂!wepoker底牌透视(透视)其实有挂(详细辅助攻略方法)1、下载好辅助软件之后点击打开,...
必看攻略!impoker辅助,... 必看攻略!impoker辅助,uupoker有透视吗,线上教程(有挂透视)1、很好的工具软件,可以解...
透视数据!拱趴大菠萝作弊方法(... 透视数据!拱趴大菠萝作弊方法(透视)确实真的是有挂(详细辅助解密教程)1、每一步都需要思考,不同水平...
重大消息!pokerworld... 1、重大消息!pokerworld软件,hhpoker是正规的吗,大神讲解(有挂辅助);详细教程。2...
透视ai代打!hhpoker智... 透视ai代打!hhpoker智能辅助插件(透视)真是真的有挂(详细辅助新2025教程)1、点击下载安...
安装程序教程!hh poker... 安装程序教程!hh poker辅助器先试用,德州透视是真的吗,透视教程(有挂神器)这是由厦门游乐互动...
透视ai代打!wepoker黑... 透视ai代打!wepoker黑侠辅助器(透视)切实真的有挂(详细辅助可靠教程)1、ai机器人多个强度...
2024教程!拱趴大菠萝开挂方... 2024教程!拱趴大菠萝开挂方法,wepoker辅助器安装包定制,插件教程(有挂技巧)1、点击下载安...
盘点一款!we-poker有人... 盘点一款!we-poker有人玩吗,wepoker透视脚本网页,玩家教程(有挂攻略);支持多人共享记...
透视了解!we poker插件... 透视了解!we poker插件(透视)好像有挂(详细辅助存在挂教程);1、系统规律教程、辅助透视等服...