输入搜索查询文字后,我会在中过滤我的卡片项目,RecyclerView
并将其显示在顶部。但是,由于某些原因清除了所有文本后,列表不会返回到原始状态。如何刷新我的RecyclerView
列表?下面的代码应该给您一个更好的主意。
@Override
public boolean onQueryTextChange(String newText) {
final List<Number> filteredModelList = filter(numbers, newText);
Log.v("App", newText + ", " + numbers.size() + ", " + filteredModelList.size());
adapter.animateTo(filteredModelList);
list.scrollToPosition(0);
adapter.notifyDataSetChanged();
if (newText.equalsIgnoreCase("")){
try{
Log.e("SEARCH VIEW", "I CAN ENTER HERE"); //But the list doesn't refresh
adapter.animateTo(numbers);
adapter.notifyDataSetChanged();
list.setAdapter(adapter);
list.scrollToPosition
} catch(Exception e){
Log.e("Caught Exception", e.toString());
}
}
return true;
}
当没有与搜索匹配的项目时,这是有问题的-屏幕只是空白,没有卡片,并且上的“ X”按钮SearchView
也不可见。当X可见并且我触摸它时,列表将返回其原始状态。第二个问题,是否有办法始终显示关闭图标(“ X”)?
请记住,您有一个将数据加载到RecyclerView中的方法,因此您要执行的操作是在IF语句中再次调用该方法,例如:当newText
长度等于时zero
,执行一些操作……
下面是算法:
if (newText.length() == 0){
//Reload the data Again , use the existing method you have of loading data in the RecyclerView .
}
如果您有任何问题,请再次在中发布代码加载数据,RecyclerView
然后我再次向您显示。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句