这个比较简单,只是将AutoCompleteTextView绑定一个ArrayAdapter就可以了。

界面布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 定义一个自动完成文本框,
指定输入一个字符后进行提示 -->
<AutoCompleteTextView
android:id="@+id/auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="请选择您喜欢的图书:"
android:dropDownHorizontalOffset="10dp"
android:completionThreshold="1"/>
<!-- 定义一个MultiAutoCompleteTextView组件 -->
<MultiAutoCompleteTextView
android:id="@+id/mauto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"/>
</LinearLayout>

主程序代码

package com.example.autocompletetextview

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.AutoCompleteTextView
import android.widget.MultiAutoCompleteTextView class MainActivity : AppCompatActivity() { // 定义字符串数组,作为提示的文本
private var books = arrayOf("aaaa", "abbbbbbb",
"abcccccccccc", "ccccccccc")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 创建一个ArrayAdapter,封装数组
val aa = ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, books)
val actv = findViewById<AutoCompleteTextView>(R.id.auto)
// 设置Adapter
actv.setAdapter(aa)
val mauto = findViewById<MultiAutoCompleteTextView>(R.id.mauto)
// 设置Adapter
mauto.setAdapter(aa)
// 为MultiAutoCompleteTextView设置分隔符
mauto.setTokenizer(MultiAutoCompleteTextView.CommaTokenizer())
}
}

最新文章

  1. iOS技术博客(文摘)链接地址
  2. 将 ASP.NET MVC3 Razor 项目部署到虚拟主机中
  3. Xcode常见错误汇总
  4. Maven-010-maven 编译报错:Failure to ... in ... was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced.
  5. SharpDX之Direct2D教程II——加载位图文件和保存位图文件
  6. spring的定时任务
  7. getdata
  8. (转)两分钟彻底让你明白Android Activity生命周期(图文)!
  9. 美工代码注意事项(html+div+css+js)
  10. PHP进口Excel至MySQL方法
  11. (基础篇 走进javaNIO)第一章-java的i/o演进之路
  12. Linux内置命令
  13. kafka快速入门
  14. 记阿里云SLB后配置Nginx反向代理百度地图API的坑
  15. noip第31课资料
  16. Linux学习之源码包安装与脚本安装(十八)
  17. Javascript阿拉伯数字转中文
  18. Centos的yum源更换为国内的阿里云源
  19. python学习笔记Day3
  20. 2.3.4volatile的原子性

热门文章

  1. abp vNext微服务框架分析
  2. sshd安全加固
  3. js的异常处理 try catch
  4. php 常用字符串函数总结
  5. 写一个python小程序
  6. 快速IO
  7. java利用反射动态获取实体类的属性值
  8. 项目兼容ie8技术要点
  9. ElementUI入门和NodeJS环境搭建
  10. zookeeper的补充