androidmaterial-designmaterial-components-androidsearchbar

Material Design SearchView has no method "setOnQueryTextListener"


I am struggling to implement material components search in my android app following this tutorial

I built a basic app with viewbinding, added implementation 'com.google.android.material:material:1.11.0' created a fragment with the default xml code given in that description, run the app, everything looks fine, i see a searchbar that i can tap to open searchView and enter a query, so far so good.

But: I am not able to implement the method to get the query and start the search, because when i try to do something like binding.searchView.setOnQueryTextListener(...) i get an error saying that method does not exist.

What am i doing wrong or miss?


Solution

  • Finally found this workaround: searchView has a child editText that you can add a text change listener to. Don't know why this is not documented in the example.

    binding.searchView.editText.addTextChangedListener { editable ->
        /* do magic */
    }