AutoCompleteTextView ArrayAdapter
AutoCompleteTextView
继承于EditText,拥有EditText所有属性和方法
在输入框中输入我们想要输入的信息就会出现其他与其相关的提示信息
首先在activity_main.xml中设置
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" > <AutoCompleteTextView
android:id="@+id/actv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="2"
android:popupBackground="@android:color/holo_blue_light"
android:hint="请输入手机" /> </RelativeLayout>
然后是AutoCompleteTextView提示框中显示的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" /> <TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>
然后在MainActivity中将AutoCompleteTextView找到,初始化数据源,设置适配器
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; public class MainActivity extends Activity { // 数据源
String[] array = { "zhangsan", "lisi", "wangwu", "zhaoliu", "tianqi",
"zhangba", "zhaojiu" }; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 显示布局
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv); // 适配器
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this, R.layout.item_layout, R.id.tv, array); //设置适配器
actv.setAdapter(adapter);
} }
运行效果如图
AutoCompleteTextView ArrayAdapter的更多相关文章
- Third Day:正式编程第三天,学习实践内容TextView跑马灯、AutoCompleteTextView、multiAutoCompleteTextView以及ToggleButton、checkedBox、RadioButton等相关实践
2.针对Focused的TextView跑马灯(文字较多一行无法显示)效果 针对单个TextView的跑马灯效果,可直接在TextView控件参数中添加三个属性: android:singleLine ...
- 安卓开发学习之AutoCompleteTextView
最近在学习安卓开发,开始是看视频学的,基本上是照着老师的操作来,但其实老师也是按照安卓的开发文档来教的,于是决定试试自己看文档来学. 今天学到AutoCompleteTextView,一上来先按照Li ...
- android之‘com.example.android.apis.view’的代码段
1.AutoCompleteTextView ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, and ...
- Android开发工程师文集-相关控件的讲解,五大布局
前言 大家好,给大家带来Android开发工程师文集-相关控件的讲解,五大布局的概述,希望你们喜欢 TextView控件 TextView控件有哪些属性: android:id->控件的id a ...
- <Android 基础(二十四)> EditText
介绍 A text field allows the user to type text into your app. It can be either single line or multi-li ...
- android 智能提示
<AutoCompleteTextView android:id="@+id/autoCompleteTextView" android:completionThreshol ...
- EditText(3)输入时自动完成功能
在android输入自动完成功能由EditText的子类 AutoCompleteTextView 实现.如下: 1,在xml中使用 <AutoCompleteTextView android: ...
- Android:控件AutoCompleteTextView 自动提示
在文本框中输入,要这样的提示效果,如果你输入的是aac,在输入aa后,选择aac,文本框的内容会自动补齐,输入aac(类似百度搜索文本框的显示结果) <AutoCompleteTextVie ...
- Android 笔记 AutoCompleteTextView day8
用于自动补全内容 适应器可用于显示多行内容 package com.supermario.autocompletedemo; import android.app.Activity; import a ...
随机推荐
- C# - 二叉树表达式计算
很早以前就写过双栈的表达式计算. 这次因为想深入学一下二叉树,网上都是些老掉牙的关于二叉树的基本操作. 感觉如果就学那些概念,没意思也不好记忆.于是动手写了一个表达式计算的应用例子. 这样学习印象才深 ...
- c#将Excel数据导入到数据库的实现代码(OleDb)
sing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web ...
- Android VideoView
这两天公司要让做一个播放视频的小Demo,于是网上学习了下VideoView的使用方法. 先看布局文件,很简单 就是一个VideoView和两个ImageView <RelativeLayout ...
- iOS 不同类之间的传值
iOS是面向对象开发的,有很多不同的类,很多时候会遇到类与类之间的"交流"需求,比如通知.传递数值等等,(通知可以用nsnotificationcenter来做, 以后总结)下面主 ...
- This system is not registered with RHN解决方法
root@localhost ipvsadm-1.25]# yum install gcc Loading "security" plugin Loading "rhnp ...
- asp.net 图片质量压缩(不改变尺寸)
private static ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCodecInfo[] encoders; en ...
- [Head First设计模式笔记]----命令模式
命令模式定义:将“请求”封装成对象,以便使用不同的请求.队列或者日志来参数化其他对象.命令模式也支持可撤销的操作. 类图: 适用设计方案举例:实现一种遥控器,该遥控器具有七个可编程的插槽(每个都可以指 ...
- md5实现
/** * @param str * @return */ public static String stringToMD5(String str, String encode) { try { by ...
- 【leetcode】62. Uniqe Paths
题目 https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m ...
- C# Attribute
Attribute 是C#非常重要的一块内容,需要研究一下. Attribute 的简单使用:简而言之,就是可以自定义通用标志位,而不是在每个所需的类型中分别增加标志位. //class专用attr ...