Edittext and filter a recyclerview


#1

Hello

I have a problem.
My recyclerview load a MultableList.

I have an EditText in this actvity.
When i edit this edittext i create a new mutablelist (filter) to asign in the adapter.
But i have a problem, the word “this” have not the correct type.

Why is my problem ?
I must create a new adapter ?

rechercheniveau.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {

nivs?.forEach { NIV ->
//println(NIV.code)
//println(p0.toString())
if (NIV.code.contains(p0.toString(),false)){
println(“EDIT”)
nivsfilter.add(NIVEAUX(NIV.code,NIV.desi,0,NIV.cptniv))

}
}
adapter = NiveauxAdapter(nivsfilter,this)

val recyclerView = findViewById(R.id.niv_recycler_view) as RecyclerView
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = adapter

}

override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
})

Thanks


#2

The ‘this’ is looking at the TextWatcher not the Activity. You need to do ‘this@[activity]’


#3

Tank’s so much.