【问题标题】:How to hide show recyclerView from SearchView?如何从 SearchView 中隐藏显示 recyclerView?
【发布时间】:2018-05-30 14:09:51
【问题描述】:

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

这里是回调函数的代码sn-p

@Override
public boolean onQueryTextChange(String newText) {

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

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

【问题讨论】:

  • 你的else声明在哪里?
  • 哈哈..你错过了else

标签: android android-recyclerview visibility searchview


【解决方案1】:

试试这个

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

【讨论】:

    【解决方案2】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      • 2012-06-25
      • 2019-01-21
      • 2019-11-09
      相关资源
      最近更新 更多