AutoCompleteTextView的使用
AutoCompleteTextView的使用
一、简介
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 >
AutoCompleteTextView的使用的更多相关文章
- Android常用组件之AutoCompleteTextView
安卓组件中,凡是需要配置数据的组件,一般都是用Adapter配置. AutoCompleteTextView的使用方法与ListView类似,也是用setAdapter来设置数据. MultiAuto ...
- Android:控件AutoCompleteTextView 自动提示
在文本框中输入,要这样的提示效果,如果你输入的是aac,在输入aa后,选择aac,文本框的内容会自动补齐,输入aac(类似百度搜索文本框的显示结果) <AutoCompleteTextVie ...
- Android 笔记 AutoCompleteTextView day8
用于自动补全内容 适应器可用于显示多行内容 package com.supermario.autocompletedemo; import android.app.Activity; import a ...
- Third Day:正式编程第三天,学习实践内容TextView跑马灯、AutoCompleteTextView、multiAutoCompleteTextView以及ToggleButton、checkedBox、RadioButton等相关实践
2.针对Focused的TextView跑马灯(文字较多一行无法显示)效果 针对单个TextView的跑马灯效果,可直接在TextView控件参数中添加三个属性: android:singleLine ...
- android内部培训视频_第三节 常用控件(Button,TextView,EditText,AutocompleteTextView)
第三节:常用控件 一.Button 需要掌握的属性: 1.可切换的背景 2.9.png使用 3.按钮点击事件 1) onClick 3) 匿名类 4) 公共类 二.TextView 常用属性 1.a ...
- DatePickerDialog、AutoCompleteTextView
DatePickerDialog选择日期,调用showDialog(int id)方法,会执行onCreateDialog方法: @Override protected Dialog onCreate ...
- AutoCompleteTextView自动补全文本框
AutoCompleteTextView的作用是在输入框中输入我们想要输入的信息,就会出现其他与其相关的提示信息 下面是实例代码: MainActivity.java package com.shao ...
- Android学习起步 - AutoCompleteTextView及MultiAutoCompleteTextView控件使用
大家在用百度搜索时,输入几个词就出现下拉框可选,以下两个控件就具有这个功能 AutoCompleteTextView:只能匹配输入的开始,只有一次匹配 MultiAutoCompleteTextVie ...
- Android 自动补全提示输入AutoCompleteTextView、 MultiAutoCompleteTextView
以在搜索框搜索时,自动补全为例: 其中还涉及到一个词,Tokenizer:分词器,分解器. 上效果图: MainActivity.java: package com.joan.testautocoml ...
- 用AutoCompleteTextView实现历史记录提示
自定义AutoCompleteTextView 博客分类: android进阶 android 网上找到的都是同ArrayAdapter一起使用的,有时候需要自定义风格,咋办?follow me! ...
随机推荐
- Powershell & SQL
一.使用Powershell插入数据到SQL中 1.方法一 $ServerName=xxx $Database=xxx $UserID=xxx $Pwd=xxx $conn=new-object Sy ...
- GO语言中使用OpenCV
GO语言中使用OpenCV - OpenCV China :图像处理,计算机视觉库,Image Processing, Computer Vision http://wiki.opencv.org.c ...
- PHP 防止恶意用户快速刷新页面
<?php /** * 防止快速刷新 * */ session_start(); header("Content-type:text/html;charset=utf-8") ...
- 为什么要使用nonlocal
Python3中加入了新的关键字nonlocal,当在一个嵌套的函数中对变量申明为nonlocal时,就明确表示这个变量是外部函数中定义的变量.也许会有这么一个问题:按照python的LEGB原则,在 ...
- Linux运维工程师:30道面试题整理
1.linux 如何挂在 windows 下的共享目录 mount.cifs //192.168.1.3/server /mnt/server -o user=administrator,pass=1 ...
- tf.clip_by_value:将tensor中的0和NONE进行范围限制的函数
tf.clip_by_value clip_by_value( t, clip_value_min, clip_value_max, name=None) Defined in ...
- python 自动获取(打印)代码中的变量的名字字串
方法一: import inspectimport re def varname(p): for line in inspect.getframeinfo(inspect.currentframe() ...
- 学会这些你就是Android 开发高手了!
世界范围内,很多移动设备都是Android系统,Android开发可以说很有前景.对于安卓开发者来说,如果有个地方可以找到Android开发所有的资料,不需要一个网站一个网站的搜索,简直是件很开心的事 ...
- 转:MVC遇上bootstrap后的ajax表单验证
使用bootstrap后他由他自带的样式has-error,想要使用它就会比较麻烦,往常使用jqueyr.validate的话只有使用他自己的样式了,而且有模型在使用模型验证更方便点.怎么解决呢? 当 ...
- windows下线程库的使用
下载PTHREAD的WINDOWS开发包 pthreads-w32-2-4-0-release.exe(任何一个版本均可) http://sourceware.org/pthreads-win32 ...