Recyclerview+EditText搜索过滤

一、Recyclerview+EditText搜索过滤
1、搜索过滤在安卓中我们会经常遇到,在顶部有个搜索框,搜索框下面用Recyclerview列表查询出数据,然后进行过滤。这种不是通过数据库查询出数据去搜索的,直接进行过滤。
搜索页面的搭建:
Recyclerview+EditText搜索过滤2、在activity中写搜索框的改变监听事件addTextChangedListener,代码截图如下:
Recyclerview+EditText搜索过滤 onTextChanged:这个方法是在Text改变之前被调用,使用过滤搜索,最重要的代码在Adapter中。
3、在Adapter实现Filterable,实现方法:
Recyclerview+EditText搜索过滤如下是过滤数据的代码,内部类的方法,如图:
Recyclerview+EditText搜索过滤Recyclerview+EditText搜索过滤For循环里的是自己需要过滤的字段,contains:包含,这个可以根据自己需要匹配。