2 years ago

#69696

test-img

Hagat

How do I implement searchview in kotlin android that works with character accents aswell?

Here is the edited code for the SearchView and working fine:

    val searchText = query!!.toLowerCase(Locale.getDefault())
                if (searchText.isNotEmpty()){
                    dbList.forEach {
                        val txtKrString = Normalizer.normalize(it.txtKr, Normalizer.Form.NFD)
                            .replace("[^\\p{ASCII}]".toRegex(), "")
                        val txtFrString = Normalizer.normalize(it.txtFr, Normalizer.Form.NFD)
                            .replace("[^\\p{ASCII}]".toRegex(), "")
                        if (txtKrString.toLowerCase(Locale.getDefault()).contains(searchText)){
                            tempdbList.add(it)
                        }else if (txtFrString.toLowerCase(Locale.getDefault()).contains(searchText)){
                            tempdbList.add(it)
                        }
                    }
                    this@Main.recyclerv.adapter!!.notifyDataSetChanged()
                }

kotlin

searchview

diacritics

0 Answers

Your Answer

Accepted video resources