这个比较简单,只是将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())
}
}

autoComplete TextView的更多相关文章

  1. html5 list属性、autocomplete属性、pattern属性

    list属性的值为某个datalist元素的id,datalist也是html5中新增的属性,类似于选择框select,或者android中的autocomplete textview控件.datal ...

  2. Android View之用户界面...

    PS:Android的控件真的是很多...现在还在忙到控件...也是神了.... 学习内容: 1.Spinner下拉菜单... 2.AutoComplete TextView自动完成文本框... 1. ...

  3. android test控件

    1.Plain Text 输入文本框 <EditText android:id="@+id/editText" android:layout_width="wrap ...

  4. 关于textview显示特殊符号居中的问题

    话说这是2017年的第一篇博客,也是一篇技术博客.先从简单的一篇解决问题开始吧,千里之行,始于足下! ------------------------------------------------- ...

  5. 奇葩问题-TextView无法获取值

    问题场景 前几天写一个界面的时候,遇到一个非常奇葩的问题.app第一次安装的时候,这里针对用户第一次安装的时候,后来是不会出现这个问题了.我明明是对某个界面的一个textview赋值了,而且服务端也返 ...

  6. autocomplete的使用

    autocomplete使用分为本地调用方法和读取远程读取数据源的方法 (1)本地调用方法 <script src="Scripts/jquery-1.4.1.min.js" ...

  7. 动态给textView加图片

    Drawable img = layout.getResources().getDrawable(R.drawable.icon); // 调用setCompoundDrawables时,必须调用Dr ...

  8. TextView使用大全

    最近打算写一个系列的android初级开发教程,预计40篇以上的文章,结合我实际工作中的经验,写一些工作中经常用到的技术,让初学者可以少走弯路,写一个系列的话,大家学习起来也有头有尾. 今天就从我们每 ...

  9. TextField和TextView的限制输入长度

    TextField的限制代理方法 只需要在这个代理方法里面code这样的代码就可以了 16 是长度可以自己设置 - (BOOL)textField:(UITextField *)textField s ...

随机推荐

  1. (Linux基础学习)第三章:terminal与shell的简介和修改命令提示符颜色

    第1节:terminal终端设备终端:键盘.鼠标.显示器物理终端(/dev/console):控制台console虚拟终端(tty:teletypewriters,/dev/tty# #为[1-6]) ...

  2. C++(四十一) — 多态、虚函数、虚析构函数、纯虚函数

     1.多态 面向对象程序设计中,多态性表现为: (1)重载多态:函数重载.运算符重载: (2)运行多态:通过基类的指针(或引用)调用不同派生类的同名函数,表现出不同的行为: (3)模板多态:参数多态, ...

  3. springboot学习笔记(二)—— springboot的启动模式设置

    把springboot的启动类图标(spring)去掉,在启动类中添加以下代码 package com.xdr.spring; import org.springframework.boot.Bann ...

  4. 《Exceptioning团队》第六次作业:团队项目系统设计改进与详细设计

    一.项目基本介绍 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 Exception 作业学习目标 1.掌握面向对象软件设计方法:2.完善系统设计 ...

  5. ajax跨域-CORS

    CORS:跨域资源共享,是一种跨域访问的W3C标准,它允许浏览器可以跨源服务器进行请求,可以让ajax实现跨域访问.出现跨域问题的原因是浏览器同源策略导致的,协议+域名+端口三者一致被认为是同源.网站 ...

  6. mysql优化后的主配置文件

    #!/bin/bash basedir=$mysql datadir=$mysql/data server_id=$(hostname -I | awk '{print $NF}'|awk -F '. ...

  7. (尚008)Vue条件渲染

    1.test008.html <!DOCTYPE html><html lang="en"><head> <meta charset=&q ...

  8. asp.net+ueditor word粘贴上传

    最近公司做项目需要实现一个功能,在网页富文本编辑器中实现粘贴Word图文的功能. 我们在网站中使用的Web编辑器比较多,都是根据用户需求来选择的.目前还没有固定哪一个编辑器 有时候用的是UEditor ...

  9. Intel 80286 CPU

    一.80286概述 INTEL 1982年推出80286芯片,该芯片相比8086和8088有了飞跃式发展,虽然它仍是16位结构,但在CPU内部含有13.4万个晶体管,时钟频率由最初6MHz逐步提高到2 ...

  10. 1090 Highest Price in Supply Chain (25)(25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...