autoComplete TextView
2024-10-21 11:31:21
这个比较简单,只是将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())
}
}
最新文章
- iOS技术博客(文摘)链接地址
- 将 ASP.NET MVC3 Razor 项目部署到虚拟主机中
- Xcode常见错误汇总
- 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.
- SharpDX之Direct2D教程II——加载位图文件和保存位图文件
- spring的定时任务
- getdata
- (转)两分钟彻底让你明白Android Activity生命周期(图文)!
- 美工代码注意事项(html+div+css+js)
- PHP进口Excel至MySQL方法
- (基础篇 走进javaNIO)第一章-java的i/o演进之路
- Linux内置命令
- kafka快速入门
- 记阿里云SLB后配置Nginx反向代理百度地图API的坑
- noip第31课资料
- Linux学习之源码包安装与脚本安装(十八)
- Javascript阿拉伯数字转中文
- Centos的yum源更换为国内的阿里云源
- python学习笔记Day3
- 2.3.4volatile的原子性