Reputation: 435
I'm trying to filter a list every time the query text of a SearchView has changed.
svComuni
is the name of the SearchView.
This is my code on my main activity:
private fun setUIControl() {
binding.svComuni.setOnQueryTextListener(textChangeListener())
}
inner class textChangeListener: SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(p0: String?): Boolean {
return findAllSimilarCountry(p0)
}
override fun onQueryTextChange(p0: String?): Boolean {
return findAllSimilarCountry(p0)
}
}
private fun findAllSimilarCountry(p0: String?): Boolean {
Log.d(TAG, p0!!)
return true
}
By using this listener I'm able to detect every change in query text of SearchView when I insert some char and when I submit, but not in case I remove the last character. So the empty query text doesn't trigger the listener. How can I include this case?
Upvotes: 0
Views: 617
Reputation: 41
Do you try to add validation to your listener methods? For example:
if (p0.equals("")) {
return false
} else {
return findAllSimilarCountry(p0)
}
Upvotes: 1