Android学习笔记13---实时搜索框
来源:互联网 发布:java去掉括号内容 编辑:程序博客网 时间:2024/06/02 02:23
AutoCompleteTextView,自动完成文本框。
用于实现允许用户输入一定字符后,显示一个下拉菜单,供用户从中选择,当用户选择某个选项后,按用户选择自动填写该文本框。
该组件继承EditText,所以它支持EditText组件提供的属性,同时,该组件该支持如下功能。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.amy.searchtest.MainActivity"><LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <AutoCompleteTextView android:id="@+id/autoCompleteTextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:completionThreshold="2" android:completionHint="请输入搜索内容..." android:layout_weight="7"/> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="搜索" android:layout_weight="1" android:layout_marginLeft="10px"/></LinearLayout></android.support.constraint.ConstraintLayout>MainActivity.java
package com.amy.searchtest;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;import android.widget.Button;import android.widget.Toast;public class MainActivity extends AppCompatActivity { public static final String[] CONTENTS = new String[]{"zg陕西","zg海南","zg新疆","zg西藏"}; AutoCompleteTextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); //创建一个ArrayAdapter适配器 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,CONTENTS); textView.setAdapter(adapter); Button button = (Button) findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, textView.getText().toString(),Toast.LENGTH_SHORT).show(); } }); }}
效果图
阅读全文
0 0
- Android学习笔记13---实时搜索框
- Android学习笔记(29):搜索框SearchView
- lucene学习笔记(七)lucene近实时搜索
- lucene学习笔记(八)lucene实时搜索
- android搜索框实时显示 |中文转拼音
- Android 搜索框的实时查询/模糊查询
- 实时图形学学习笔记
- Android学习笔记:搜索(一)- 概述
- android学习笔记之搜索手机文件
- 学习笔记 Android.mk 自动搜索
- Android 学习笔记之实时保存数据-现场保护
- Android 学习笔记之实时保存数据-现场保护 onSaveInstanceState()
- lucene学习之近实时搜索
- Android中如何优化实时搜索
- Android搜索实时显示功能实现
- web学习笔记13-移动端搜索框提示功能
- 操作系统学习笔记:实时系统
- 实时搜索
- [cnblogs镜像]页面定制CSS代码初探(二):自定义h2标题样式 添加阴影 添加底色 等
- 【洛谷3335】【ZJOI2013】蚂蚁寻路
- [cnblogs镜像]Xcode 下“ did not have any applicable content ”分析及解决
- android-SVG
- [cnblogs镜像]Xcode7 下导入第三方库 图文介绍
- Android学习笔记13---实时搜索框
- Linux操作系统命令学习第四天
- Django入门-6:视图-中间件、CSRF
- Algorithm5——排序算法
- matlab permute函数
- Ubuntu下LAMP环境搭建 Apache、MySQL、PHP
- [cnblogs镜像]AFNetworking 提示"The resource could not be loaded because the App Transport Security
- Tomcat 可以运行但localhost:8080打不开
- Delphi东京版FireDAC连接MSSQL2000