how to get the events of searchview in android

后端 未结 6 893
傲寒
傲寒 2020-12-15 04:58

I\'m using a search view in my application. Now i just want to get the text typed in the SearchView text box and display it on another textview. If i typed the text and clic

6条回答
  •  孤城傲影
    2020-12-15 05:29

    The right way to solve this is to use setOnQueryTextListener

    This is a small exmple using Kotlin:

    txtSearch = rootView.searchView 
    txtSearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
    
            override fun onQueryTextChange(newText: String): Boolean {
                return false
            }
    
            override fun onQueryTextSubmit(query: String): Boolean {
                return false
            }
     })
    

提交回复
热议问题