删除查询android时更新searchView

时间:2017-10-31 00:25:33

标签: android kotlin

我使用自定义可搜索的ListAdapter实现了searchView。目前使用我的代码,我可以实现我想要的大部分功能。但是,当我按退格键删除要查询的字符串时,查询结果不会在SearchView内部更新。我是否实现了onQueryTextChange()错误?

MainActivity:

    val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager

    val searchMenuItem = menu!!.findItem(R.id.search)

    val searchView = searchMenuItem.actionView as SearchView

    searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName))

    searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener{
        override fun onQueryTextSubmit(query: String?): Boolean {
            (listView.adapter as MessageListAdapter).filter.filter(query)
            return true
        }

        override fun onQueryTextChange(newText: String?): Boolean {
            (listView.adapter as MessageListAdapter).filter.filter(newText)
            return true
        }
    }) 

0 个答案:

没有答案