很多事后我们需要用到SearchView文字与RcyclerView进行动态匹配,比如说歌词的关键字索引,列表查询等 那么这里就介绍一种常用的方案:

https://github.com/FishInWater-1999/android-SignInSystem
/*
SearchView 文字变化 动态匹配
*/
private void iniSearch(){
setTextColor();
mSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
List mList = ListContentMate.mate(mUserTotalList, mSearch.getQuery().toString());
userList.clear();
userList.addAll(mList);
recyclerAdapter.notifyDataSetChanged();
return false;
}
});
}注:ListContentMate 是我自定义的类,内容如下
/**该类由于将 list 与 字符串进行配对
* 检索出符合条件的 List
* @author fishinwater
*/
public class ListContentMate {
public static List mate(List mList, String fullName){
List newList = new ArrayList<>();
for (int i = 0 ; i < mList.size() ; i++){
if (mList.get(i).getFullname().contains(fullName)){
newList.add(mList.get(i));
}
}
return newList;
}
}在给出的第一块代码中的这三行:
userList.clear();
userList.addAll(mList);
recyclerAdapter.notifyDataSetChanged();结束,欢迎关注我获得跟多小姿势~~
关于 recyclerView 的基本使用:https://blog.csdn.net/qq_43377749/article/details/89813275