skip to Main Content

I’m using a SearchView in my application. Now I just want to get the text typed in the SearchView and do something this it. But I don’t want to use any extra buttons. I just want to get the result when I’m typing in SearchView box.

2

Answers


  1. Chosen as BEST ANSWER

    it's will solve some thing like this in kotlin :

    searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener,
            androidx.appcompat.widget.SearchView.OnQueryTextListener {
            override fun onQueryTextSubmit(p0: String?): Boolean {
                return false
            }
    
            override fun onQueryTextChange(p0: String?): Boolean {
                // do your work ..
                return false
            }
        })
    

  2. You should use onQueryTextChange().

    For example:

     searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
                override fun onQueryTextSubmit(query: String?): Boolean {
                    // Called when the user submits the query.
                    return false
                }
     
                override fun onQueryTextChange(newText: String?): Boolean {
                    // Called when the query text is changed by the user.
                    return false
                }
    })
    

    You can check for more information: https://developer.android.com/reference/android/widget/SearchView.OnQueryTextListener

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search