当前位置: 首页 > 面试题库 >

在SearchView中限制onQueryTextChange

葛修永
2023-03-14
问题内容

“节流”的最佳方法是什么,onQueryTextChange这样我的performSearch()方法每秒才调用一次,而不是每次用户键入一次?

public boolean onQueryTextChange(final String newText) {
    if (newText.length() > 3) {
        // throttle to call performSearch once every second
        performSearch(nextText);
    }
    return false;
}

问题答案:

我最终得到了一个类似于下面的解决方案。这样,它应该每半秒发射一次。

        public boolean onQueryTextChange(final String newText) {

            if (newText.length() > 3) {

                if (canRun) {
                    canRun = false;
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {

                            canRun = true;
                            handleLocationSearch(newText);
                        }
                    }, 500);
                }
            }

            return false;
        }


 类似资料:
  • 我创建了一个基于,它应该通过

  • 问题内容: 我正在通过migrations.changeColumn函数在迁移中添加一个约束。 添加约束是可行的,但是由于您需要提供Possibly unhandled SequelizeDatabaseError: relation “myAttribute_unique_idx” already exists`。 (使用的数据库是postgres) 我也尝试过使用removeIndex 但是在

  • Android example SearchView with search filter Using GitHub API user followers Example. Bonus - simple API Service (Java) Using Retrofit2 + rxJava2 + GitHub API Example.

  • 我正在尝试隐藏ActionBar中的子菜单和SearchView。我在用ActionBarsherlock。 我想通过点击按钮隐藏子菜单和SearchView

  • 问题内容: 在我的elasticsearch索引“ people”中,包含以下文件: 我想得到一个文档的结果,该文档的分区为2或1,但是最多只能包含2个。因此,如果以上是我的整个索引,我希望它返回: 用Elastic中的单个查询是否可以实现此目标?非常感谢您的帮助! 问题答案: 这样的事情应该做到:

  • 问题内容: 我的代码中有此导入: 但我得到以下错误: 并且如果它可以帮助我的IDE蚀,我该如何解决此错误? 问题答案: 在这里看看:由于对所需库rt.jar的限制而导致对类的访问限制? 它并非与您的问题完全相同,但有些答案是相关的。这是引号: http://www.digizol.com/2008/09/eclipse-access-restriction-on- library.html 最适合