【问题标题】:SearchView in android Shows nothing in the listandroid中的SearchView在列表中不显示任何内容
【发布时间】:2019-01-03 21:47:51
【问题描述】:

此代码无法正常工作。每当我搜索一个以大写字母开头的项目时,它在列表中什么都不显示。它只显示以小字母开头的字母。

@Override
    public boolean onQueryTextChange(String s) {
        String userinput= s.toLowerCase();
        List<MultipleFoodWraper> newlist = new ArrayList<>();
        for(MultipleFoodWraper name :multipleFoodWraperArrayList) {
            if (name.getName().toString().contains(userinput)) {
                newlist.add(name);
            }

            adapter.updatelist(newlist);
        }
        return true;
    }

【问题讨论】:

  • 我不知道 name 变量在哪里用值初始化或它持有什么,但这个 s.toLowerCase(); 不应该是您问题的主要原因吗?
  • 对比的时候你试过name.getName().toString().toLowerCase()吗?
  • @LeoPelozo 谢谢这么多它的工作????????

标签: android searchview


【解决方案1】:

name 转换为小写即可 name.getName().toString().toLowerCase().contains(userinput)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    相关资源
    最近更新 更多