Android教程(十五)-- 自动提示框的使用
来源:互联网 发布:高校辅导员网络培训 编辑:程序博客网 时间:2024/06/04 19:14
本章我们将会说说,自动提示框AutoCompleteTextView的使用。
相信我们使用百度或者谷歌等搜索的时候,在输入框输入一个字,输入框下面就会出现相关的提示。
其实这个功能会为我们带来很多便利,我们来看看它是怎么实现的。
第一步,建立一个工程Ep.AutoCompleteTextView.
第二步,随便设计一下视图。
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <AutoCompleteTextView android:id="@+id/autoCompleteTextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="16dp" android:ems="10" > <requestFocus /> </AutoCompleteTextView></RelativeLayout>
第三步,写核心文件。
package com.example.ep.autocompletetextview;import android.os.Bundle;import android.app.Activity;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;public class MainActivity extends Activity {private AutoCompleteTextView atct;private static final String[] autoStrs = new String[]{"J","Jo","Jov","Jove","Joven"}; @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);atct=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,autoStrs);atct.setAdapter(adapter);}}
Ok大功告成,看看预览:
不知道是不是我的样式没设置好,提示框的字体颜色是白色的,背景也是白色的所以看不清,要选中才看清楚。
- Android教程(十五)-- 自动提示框的使用
- android-----(自动提示)AutoCompleteTextView的使用
- CodeRush使用教程十五:代码修复提示
- android学习:自动提示AutoCompleteTextView的使用
- Android高手进阶教程(十五)---Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android 自动提示框
- 史上最简单的 MySQL 教程(十五)「列属性 之 自动增长」
- AutoCompleteTextView的使用(EditText自动提示)
- Android高手进阶教程(十五)之---通过Location获取Address的使用!
- Android高手进阶教程(十五)之---通过Location获取Address的使用!
- Android高手进阶教程(十五)之---通过Location获取Address的使用!
- Android高手进阶教程(十五)之---通过Location获取Address的使用!
- Android高手进阶教程(十五)之---通过Location获取Address的使用!
- Android高手进阶教程(十五)之---通过Location获取Address的使用!
- Android高手进阶教程(十五)之---通过Location获取Address的使用!
- Android高手进阶教程(十五)之---通过Location获取Address的使用!
- Android开发自动提示框
- android 中的自动提示框
- Android主题与样式(1)
- mysql下修改字符编码
- 《程序员的第一年》---------- C# 获得目录的一些方法
- Lucene教程详解
- ibatis插件的安装方式
- Android教程(十五)-- 自动提示框的使用
- C++经典书籍推荐
- mongodb 操作命令
- 今年高校毕业生将达699万
- _variant_t 数据类型介绍
- iBATIS框架源码剖析
- Java Socket实战之二:多线程通信
- Ajax读取数据
- Resource interpreted as Image but transferred with MIME type text/plain 警告解决方案