自己主动完毕文本框(AutoCompleteTextView)

java.lang.Object;

android.view.View;

android.view.TextView;

android.widget.EditText;

android.widget.AutoCompleteTextView;

MultiAutoCompleteTextView;

AutoCompleteTextView 类方法

AutoCompleteTextView 演示样例

完整project:http://download.csdn.net/detail/sweetloveft/9408072

下述程序中主要学习 AutoCompleteTextView 的用法,该控件无法在布局文件里指定 android:entries,临时没有查证有没有其它指定的方法,因此决定採用代码载入。还有一个须要注意 layout 中 <requestFocus /> 的使用。

1.MainActivity.java

package com.sweetlover.activity;

import com.sweetlover.autocompletetextviewdemo.R;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; public class MainActivity extends Activity { private static final String[] phoneNumber = new String[]{
"111234", "133126", "303404", "796863"
}; private AutoCompleteTextView autoTextView = null; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, phoneNumber);
autoTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
autoTextView.setAdapter(adapter);
}
}

2.activity_main.xml

<?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:padding="30dp"
android:orientation="vertical" > <AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="@string/note"
android:ems="20" > <requestFocus />
<!-- http://zhangkun716717-126-com.iteye.com/blog/802201 -->
</AutoCompleteTextView> </LinearLayout>

3.string.xml

<resources>

    <string name="app_name">AutoCompleteTextViewDemo</string>
<string name="note">输入电话号码</string> </resources>

4.AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sweetlover.autocompletetextviewdemo"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.sweetlover.activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application> </manifest>

阅读《Android 从入门到精通》(12)——自己主动完毕文本框的更多相关文章

  1. Android开发系列(二十):AutoCompleteTextView(自己主动完毕文本框)的功能和使用方法

    当用户输入一定的字符之后,自己主动完毕文本框可以显示一个下拉菜单,供用户从中选择,当用户选择某个菜单项之后,AutoCompleteTextView可以依照用户的选择自己主动填写该文本框 AutoCo ...

  2. Android从入门到精通pdf+书源代码

    不须要积分,免费放送 Android从入门到精通的pdf,入门的好书籍,因为csdn文件大小的限制所以分成了两部分. part1地址:http://download.csdn.net/detail/a ...

  3. android 弹出的软键盘遮挡住EditText文本框的解决方案

    1.android 弹出的软键盘遮挡住EditText文本框的解决方案: 把Activit对应的布局文件filename.xml文件里的控件用比重设置布局.(例如:android:layout_wei ...

  4. Android自己主动提示文本框(AutoCompleteTextView)

    自己主动提示文本框(AutoCompleteTextView)能够加强用户体验,缩短用户的输入时间(百度的搜索框就是这个效果). 首先.在xml中定义AutoCompleteTextView控件: a ...

  5. Android Volley入门到精通:使用Volley加载网络图片

    在上一篇文章中,我们了解了Volley到底是什么,以及它的基本用法.本篇文章中我们即将学习关于Volley更加高级的用法,如何你还没有看过我的上一篇文章的话,建议先去阅读Android Volley完 ...

  6. 阅读《Android 从入门到精通》(9)——多项选择

    多项选择(CheckBox) CheckBox 类是 Button 的子类,层次关系例如以下: android.widget.Button android.widget.CompoundButton ...

  7. 阅读《Android 从入门到精通》(17)——进度条

    进度条(ProgressBar) java.lang.Object; android.view.View; android.widget.ProgressBar; ProgressBar 类方法 Pr ...

  8. 阅读《Android 从入门到精通》(24)——切换图片

    切换图片(ImageSwitcher) java.lang.Object; android.view.View; android.widget.ViewGroup; android.widget.Fr ...

  9. 阅读《Android 从入门到精通》(33)——Intent 分类

    Intent 分类 显式 Intent:Intent("android.intent.action.CALL", Uri.parse("tel:" + stri ...

随机推荐

  1. web storage 离线存储

    用来保存键值对数据,数据以属性的方式保存在storage实例对象上   可以用storage1.length来决定键值对的数量,但是无法决定数据的大小,storage1.remainingSpace可 ...

  2. PHP静态化技术

    很多框架的模板引擎都有页面静态化的功能  目的是为了优化网站运行时间 静态化分两种  纯静态和伪静态 一. 纯静态 纯静态展示的是实实在在的静态页面 运行PHP程序 判断是否存在静态页 如果存在 展示 ...

  3. riot.js教程【三】访问DOM元素、使用jquery、mount输入参数、riotjs标签的生命周期

    前文回顾 riot.js教程[二]组件撰写准则.预处理器.标签样式和装配方法 riot.js教程[一]简介 访问DOM元素 你可以通过this.refs对象访问dom元素 而且还有大量的属性简写方式可 ...

  4. C#执行PowserShell 脚本

    Windows PowserShell能够很简洁 快速通过Script脚本方式获得我们想要执行效果. 如何在C#中任意执行PowerShell脚本.?类似目前我要在做一个进程管理工具. 通过Power ...

  5. 一次触摸,Android到底干了啥

    WeTest 导读 当我们在写带有UI的程序的时候,如果想获取输入事件,仅仅是写一个回调函数,比如(onKeyEvent,onTouchEvent-.),输入事件有可能来自按键的,来自触摸的,也有来自 ...

  6. 设计模式的征途—12.享元(Flyweight)模式

    现在在大力推行节约型社会,“浪费可耻,节俭光荣”.在软件系统中,有时候也会存在资源浪费的情况,例如,在计算机内存中存储了多个完全相同或者非常相似的对象,如果这些对象的数量太多将导致系统运行代价过高.那 ...

  7. MySQL GTIDs(global transaction identifiers)

    1.如何定义和生成GTIDs 唯一性:在所有主从库都是唯一的,由二元组构成 每个事务和GTIDs之间都有1:1映射 GTID = source_id:transaction_id source_id标 ...

  8. Go环境搭建

    Linux系统golang环境搭建 1.下载安装包go1.8.linux-amd64.tar golang安装包下载地址:https://golang.org/dl/    ( 有可能被FQ) 2.解 ...

  9. 阿里云VPS搭建Hexo博客

    最近买了一个阿里云服务器,准备写自己的网站,和将自己的作品放在上面:开始的时候,感觉就一个服务器应该很简单,但是从申请域名到备案,再到服务器搭建,没想到一波三折:闲话不多说,只是记录我在搭建时,最简单 ...

  10. android堆栈调试--详细

    1.将ndk中的arm-linux-androideabi-addr2line可执行文件的路径加入配置文件~/.bashrc中,例如: export PATH=$PATH:~/dlna/android ...