`
Bauble
  • 浏览: 66955 次
  • 性别: Icon_minigender_1
  • 来自: Mercury
社区版块
存档分类
最新评论

Android27_AutoCompleteTextView

阅读更多

 

一、创建AutoCompleteTextView

       1.在布局文件中声明一个AutoCompleteTextView

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="text" />
<AutoCompleteTextView android:id="@+id/actv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"/> 

       2.定义提示条目的样式,创建布局文件:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp"
    android:textColor="#000">
</TextView>

         3.创建一个ArrayAdapter,用来提供数据:

autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.actv);
List<String> list = new ArrayList<String>();
list.add("allotory");
list.add("bauble");
list.add("baobo");
list.add("album");
list.add("alow");
list.add("array");

        4.AutoCompleteTextView设置数据

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.item ,list);
        autoCompleteTextView.setAdapter(arrayAdapter);

 完整代码:

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text" />
<AutoCompleteTextView android:id="@+id/actv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"/>
</LinearLayout>

 Item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp"
    android:textColor="#000">
</TextView>

 AutoCompleteTextViewActivity.java

package com.android.activity;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class AutoCompleteTextViewActivity extends Activity {
	private AutoCompleteTextView autoCompleteTextView = null;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        autoCompleteTextView = 
			(AutoCompleteTextView)findViewById(R.id.actv);
        List<String> list = new ArrayList<String>();
        list.add("allotory");
        list.add("bauble");
        list.add("baobo");
        list.add("album");
        list.add("alow");
        list.add("array");
        ArrayAdapter<String> arrayAdapter = 
			new ArrayAdapter<String>(this,R.layout.item ,list);
        autoCompleteTextView.setAdapter(arrayAdapter);
    }
}

 运行结果:


  • 大小: 66.5 KB
  • 大小: 75 KB
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    TestCompleteText_AutoCompleteTextView和TextWatcher结合使用

    在Android开发中,AutoCompleteTextView和TextWatcher是两个非常重要的组件,它们可以帮助我们实现丰富的文本输入交互功能。本文将深入探讨这两个组件,并结合实例展示如何将它们结合起来使用,以实现关键词下拉提示...

    Android_AutoCompleteTextView

    **Android AutoCompleteTextView详解** 在Android开发中,`AutoCompleteTextView`是一个非常实用的控件,它能够为用户输入提供动态的建议或提示,提升用户体验。这个控件类似于搜索引擎的自动补全功能,当用户在...

    android 百度地图 AutoCompleteTextView联想刷新实现检索

    android 百度地图 AutoCompleteTextView联想刷新实现检索 很全面的

    android中AutoCompleteTextView使用

    在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它提供了自动补全功能,用户在输入时可以接收到下拉列表的建议,提高了输入效率。`MultiAutoCompleteTextView` 是 `AutoCompleteTextView` 的扩展,...

    Android自动文本填充AutoCompleteTextView

    在Android开发中,AutoCompleteTextView是一个非常实用的控件,它允许用户在输入时自动显示匹配的建议列表,极大地提高了用户体验。本实例将深入探讨如何使用AutoCompleteTextView,并结合具体的...

    android使用AutoCompleteTextView自定义适配器样式

    在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它允许用户在输入时自动显示匹配的建议列表。通常,我们使用`ArrayAdapter`来连接数据源和`AutoCompleteTextView`,但有时默认的功能可能无法满足...

    Android自定义AutoCompleteTextView

    在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它允许用户在输入时自动显示匹配的建议列表,通常用于实现搜索建议或者补全功能。本篇将深入探讨如何自定义`AutoCompleteTextView`,以满足特定的...

    Android仿百度谷歌自动提示——AutoCompleteTextView

    本文将详细介绍如何在Android中仿照百度和谷歌的自动提示功能,利用`AutoCompleteTextView`控件来实现这一功能。 `AutoCompleteTextView`是Android SDK中的一个视图组件,它继承自`EditText`,增加了自动补全的功能...

    android之AutoCompleteTextview控件

    在Android开发中,`AutoCompleteTextView` 是一个非常实用的控件,用于提供用户输入时的自动补全功能。这个控件能够显著提升用户体验,因为它能够根据用户输入的部分字符快速匹配并显示可能的选择,帮助用户更快地...

    android auto_complete_text

    在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它允许用户在输入时自动显示匹配的建议列表,从而提升用户体验。标题"android auto_complete_text"表明我们将讨论的是如何自定义和优化这个控件。 ...

    AutoCompleteTextView

    AutoCompleteTextView是Android开发中一个常用的UI组件,它属于EditText的一种扩展,主要功能是在用户输入时提供自动补全建议。这个简单的例子展示了如何利用自定义布局来实现AutoCompleteTextView的功能,使得用户...

    Android高级组件AutoCompleteTextView自动完成文本框使用详解

    Android 高级组件 AutoCompleteTextView 自动完成文本框使用详解 AutoCompleteTextView 是 Android 中的一种高级组件,用于实现自动完成文本框的功能。它可以允许用户输入一定字符后,显示一个下拉菜单,供用户从中...

    android控件--AutoCompleteTextView

    **Android控件——AutoCompleteTextView详解** 在Android开发中,AutoCompleteTextView是一个非常实用的控件,它提供了自动补全的功能,通常用于输入框中帮助用户快速选择或输入内容。这个控件基于EditText,增加了...

    自定义AutoCompleteTextView下拉列表控件

    在Android开发中,`AutoCompleteTextView` 是一个非常常见的组件,它用于实现自动补全功能,通常用于输入框中提供用户可能输入的建议。在给定的标题“自定义AutoCompleteTextView下拉列表控件”中,我们可以理解为...

    Android中AutoCompleteTextView的使用步骤.pdf

    AutoCompleteTextView是Android开发中一个常用的UI组件,它在用户输入文本时提供自动补全功能,极大地提高了用户体验。本文将详细介绍如何在Android中使用AutoCompleteTextView。 1. **AutoCompleteTextView的基本...

    AutoCompleteTextView从服务器上获得数据显示下拉列表

    AutoCompleteTextView是Android系统提供的一种可以自动补全的文本输入控件,它允许用户在输入时根据已有的数据集匹配并显示建议的选项。这个功能通常用于搜索框、地址输入等场景,提升用户体验。在本主题中,我们将...

Global site tag (gtag.js) - Google Analytics