Android用户输入自动提示控件AutoCompleteTextView使用方法
作者:饭饭_fan 发布时间:2022-02-25 14:59:50
一、简介
1、AutoCompleteTextView的作用
2、AutoCompleteTextView的类结构图
也就是拥有EditText的各种功能
3、AutoCompleteTextView工作原理
AutoCompleteTextView的自动提示功能肯定需要适配器提供数据
4、Android里的适配器
5、适合AutoCompleteTextView的适配器
ArrayAdapter
二、AutoCompleteTextView实现自动提示的方法
1)AutoCompleteTextView实现自动提示的方法
第一步、创建适配器
String[] arr={"凯撒","凯撒广场","凯撒大帝"};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.textview, arr);
第二步、AutoCompleteTextView对象应用适配器
autoCompleteTextView1.setAdapter(adapter);
说明:
提示文本是用textview实现的,提示文本里面的提示数据就是String[] arr。
三、代码实例
代码:
fry.Activity01
package fry;
import com.example.AutoCompleteTextViewDemo1.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class Activity01 extends Activity{
private AutoCompleteTextView autoCompleteTextView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity01);
autoCompleteTextView1=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
/*
* AutoCompleteTextView实现自动提示的方法
* 第一步、创建适配器
* 第二步、AutoCompleteTextView对象应用适配器
*
*/
String[] arr={"凯撒","凯撒广场","凯撒大帝"};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.textview, arr);
autoCompleteTextView1.setAdapter(adapter);
}
}
fry.Activity01
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
/AutoCompleteTextViewDemo1/res/layout/textview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- 这里是直接TextView,而不是layout下的TextView -->
</TextView >
四、易错点
1、这里是直接TextView,而不是layout下的TextView
/AutoCompleteTextViewDemo1/res/layout/textview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- 这里是直接TextView,而不是layout下的TextView -->
</TextView >
来源:http://www.cnblogs.com/Renyi-Fan/p/7286939.html


猜你喜欢
- 1.修改主站点的elasticsearch.yml添加一下行:xpack.security.enabled: true2.生成安全秘钥切到E
- Word是我们日常生活、学习和工作中必不可少的文档处理工具。精致美观的文档能给人带来阅读时视觉上的美感。在本篇文章中,将介绍如何使用组件Fr
- Android客户端请求服务器端的详细解释1. Android客户端与服务器端通信方式: Android与服务器通信通常采用HTTP通信方式
- 1 简介先来一张效果图TIM图片.gif上图中灰色的一块是ImageView控件,ImageView中的图片进行左右上下移动,以及双指缩放。
- 自然排序TreeSet集合在存储数据时有一定的顺序,它会将一些数据进行比较,比较调用的是comparaTo()方法,该方法是在Compara
- 目录概述代码实现代码地址概述多线程(multithreading),是指从软件或者硬件上实现多个线程并发执行的技术。具有多线程能力的计算机因
- 背景SpringBoot的应用监控方案比较多,SpringBoot+Prometheus+Grafana是目前比较常用的方案之一。它们三者之
- 前言前段时间一直使用到word文档转pdf或者pdf转word,寻思着用Java应该是可以实现的,于是花了点时间写了个文件转换工具源码wel
- 数组作为函数的参数传递首地址。A进行修改,a同时也会进行修改。数组参数的传递机制来源:https://blog.csdn.net/weixi
- 项目结构:运行效果:========================================================下面是代
- 创建文件或文件夹您可通过编程方式在您的计算机上创建文件夹、子文件夹和子文件夹中的文件,并将数据写入文件。public class Creat
- 近年来,二维码的使用越来越风生水起,笔者最近手头也遇到了一个需要使用二维码扫码登录网站的活,所以研究了一下这一套机制,并用代码实现了整个流程
- 本文介绍了Spring Boot 开发REST接口最佳实践,分享给大家,具体如下:HTTP动词与SQL命令对应GET从服务器获取资源,可一个
- Java中有两类线程:User Thread(用户线程)、Daemon Thread(守护线程)用户线程即运行在前台的线程,而守护线程是运行
- Android中的消息处理机制大量依赖于Handler。每个Handler都有对应的Looper,用于不断地从对应的MessageQueue
- AES简介AES(The Advanced Encryption Standard)是美国国家标准与技术研究所用于加密电子数据的规范。它被预
- 本文实例为大家分享了Android实现拍照添加时间水印的具体代码,供大家参考,具体内容如下效果如下图 :1、拍照// 非空判断 拍照?if
- 一、概述平衡二叉树具有以下性质:它是一 棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树。这个方案很好的
- 在市面上很多的APP都使用了对图片作模糊化处理后作为背景的效果,来使得整个页面更具有整体感。如下就是网易云音乐的音乐播放页面:很明显这个页面
- ref和out都是C#中的关键字,所实现的功能也差不多,都是指定一个参数按照引用传递。对于编译后的程序而言,它们之间没有任何区别,也就是说它