怎么在Android应用中实现一个动态匹配输入的内容功能?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

一、AutoCompleteTextView
独特属性:android:completionThreshold=”2”—–设置输入多少字符时自动匹配
首先,我们先在res文件夹(我用的是AndroidStudio)下的active_main.xml下面加入AutoCompleteTextView控件,并设置好大小宽高等其他一些基础属性
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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.example.admin.demo.MainActivity"> <AutoCompleteTextView android:completionThreshold="2" android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入你要搜索的关键词" /> </LinearLayout>