Alejandro Vargas
Alejandro Vargas

Reputation: 89

How to filter integer value based on string parameter input on list on kotlin?

I am trying to filter an object type list based on a string value which is working fine, but now I need to filter based on an integer attribute of the objects on the list.

Say the object.name is "name", so when I start typing just "na" the filters works properly, but for the integer filter I cannot figure it out. It just filters when the user inputs the entire number.

return objectList.filter { it.name.contains(filter) || it.pCode == filter.toInt() }

I know that the way is comparing "==" only returns when is equal, but I do not know something like contains but for numbers.

Upvotes: 0

Views: 398

Answers (1)

jvargas
jvargas

Reputation: 843

Try this

it.pCode.toString().contains(filter) 

Upvotes: 2

Related Questions