1

I want to make a filter for my RecyclerView , I find how to do that in Java but I want to implement this in Kotlin , this code is placed into Adapter class.

private Filter exampleFilter = new Filter() {
    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
        return null;
    }
    @Override
    protected void publishResults(CharSequence constraint , FilterResults results) {}
};

How this code can be used for kotlin? Here is the full code for Adapter class https://pastebin.com/a2dj30By

user1506104
  • 6,554
  • 4
  • 71
  • 89
Valentin
  • 1,159
  • 1
  • 11
  • 22
  • 1
    have you checked this yet? https://kotlinlang.org/docs/reference/object-declarations.html#object-expressions – user1506104 Feb 08 '19 at 18:21
  • use an adapter that already implements `Filterable` interface – pskink Feb 08 '19 at 19:57
  • so why dont you want to use an adapter that already implements `Filterable` interface? why do you want to reinvent the wheel? – pskink Feb 10 '19 at 07:48
  • I watched a tutorial , i'm a beginer – Valentin Feb 10 '19 at 11:02
  • so extend [this](https://gist.github.com/pskink/cd3bbdd742b5b1905a790c76831b5d85) adapter - here you have some sample [CurrencyAdapter](https://pastebin.com/raw/LEena3pM) - this is a working `Filterable` adapter that shows currency names / symbols – pskink Feb 10 '19 at 11:12
  • Thanks, I will try to implement this soon – Valentin Feb 10 '19 at 11:19

1 Answers1

4
private val exampleFilter = object : Filter() {
   override fun performFiltering(constraint: CharSequence): Filter.FilterResults? {
      //TODO do stuff
      return null
   }

   override fun publishResults(constraint: CharSequence, results: Filter.FilterResults) {
      //TODO do stuff
   }
}
CMcAllister
  • 176
  • 1
  • 5