如何从SearchView隐藏show recyclerView?

时间:2017-12-16 17:03:15

标签: android android-recyclerview visibility searchview

我有一个recyclelerView,它显示了一个项目列表。我想要实现的是,当我输入一个单词时,recyclerView应该消失,当没有文本时,recyclelerView应该重新出现。问题是recyclerView成功隐藏但是当我清除searchView中的文本时它不再出现。

  

以下是回调函数的代码片段

@Override
public boolean onQueryTextChange(String newText) {

    if(newText.length()==0)
    {
        historyRecyclerView.setVisibility(View.VISIBLE);
    }
    else
    {
        historyRecyclerView.setVisibility(View.INVISIBLE);
    }

    // musicAdapter.filter(newText);
    return true;
}

2 个答案:

答案 0 :(得分:2)

试试这个

if(newText == null || newText.length()){
    historyRecyclerView.setVisibility(View.VISIBLE);
}else{
    historyRecyclerView.setVisibility(View.INVISIBLE);
}

答案 1 :(得分:0)

  

尝试

if(nextText.isEmpty)
  {
  historyRecyclerView.setVisibility(View.VISIBLE);
}else{
historyRecyclerView.setVisibility(View.INVISIBLE);
 }