Android实现动态自动匹配输入的内容

 更新时间:2018年08月10日 08:37:07   作者:流年若逝  
这篇文章主要为大家详细介绍了Android实现动态自动匹配输入的内容,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Android实现动态自动匹配输入内容的具体代码,供大家参考,具体内容如下

用这两个控件

分别实现这两个:

package com.example.autocomplete;
 
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
 
public class MainActivity extends Activity {
 private AutoCompleteTextView acTextView;
 private String[] res = {"xxz1","xxz2","xxz3","shanghai1","shanghai2"};
 
 
 private MultiAutoCompleteTextView MulacTextView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
    
    //需要适配器
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,res);
    //初始数据源,去匹配文本框中输入的内容,然后绑定
    acTextView.setAdapter(adapter);
    
    MulacTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
    MulacTextView.setAdapter(adapter);
    //设置以逗号为分隔符结束的符号
    MulacTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    
   
}

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
 
  <AutoCompleteTextView
    android:hint="请输入搜索的关键词"
    android:completionThreshold="3"
    android:id="@+id/autoCompleteTextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
     >
 
  </AutoCompleteTextView>
 
  <MultiAutoCompleteTextView
    android:hint="请输入搜索的邮件关键词"
    android:id="@+id/multiAutoCompleteTextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    
  </MultiAutoCompleteTextView>
 
  <CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />
 
</LinearLayout>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Android中WindowManager与WMS的解析

    Android中WindowManager与WMS的解析

    今天小编就为大家分享一篇关于Android中WindowManager与WMS的解析,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-01-01
  • Android自定义加载loading view动画组件

    Android自定义加载loading view动画组件

    这篇文章主要为大家详细介绍了Android自定义加载loading view动画组件的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-08-08
  • Android Kotlin全面详细类使用语法学习指南

    Android Kotlin全面详细类使用语法学习指南

    这篇文章主要为大家介绍了Android Kotlin全面详细类使用语法学习指南,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-06-06
  • ExpandableListView实现简单二级列表

    ExpandableListView实现简单二级列表

    这篇文章主要为大家详细介绍了ExpandableListView实现简单二级列表,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-11-11
  • 一文详解Android FCM接入

    一文详解Android FCM接入

    这篇文章主要为大家介绍了Android FCM接入详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03
  • Android实现百度地图两点画弧线

    Android实现百度地图两点画弧线

    这篇文章主要为大家详细介绍了Android实现百度地图两点画弧线,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-01-01
  • Android封装对原生Log进行封装的操作

    Android封装对原生Log进行封装的操作

    这篇文章主要介绍了Android封装对原生Log进行封装的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-08-08
  • Android Intent 用法全面总结及实例代码

    Android Intent 用法全面总结及实例代码

    这篇文章主要介绍了Android Intent 用法全面总结的相关资料,并附实例代码,需要的朋友可以参考下
    2016-09-09
  • Android实现短信验证功能

    Android实现短信验证功能

    这篇文章主要为大家详细介绍了Android实现短信验证功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-05-05
  • Android 详解Studio引用Library与导入jar

    Android 详解Studio引用Library与导入jar

    这篇文章主要介绍了Android Studio引用Library与导入jar的相关资料,需要的朋友可以参考下
    2017-01-01

最新评论