I am trying to validate an array in Android app written with Kotlin. It is an array of objects. This is the code that always returns 0. This might be even some deeper problem, but for now i am looking for any other way to get the count right.
private fun count(array: Array<Item>): Int {
val selectedItemCount = 0
array.forEach { item ->
if (item.isSelected) selectedItemCount + 1
}
return selectedItemCount
}
Basically my problem is that if the count is 0 and none items are selected i want to display no items selected message, otherwise navigate to next screen. I believe that i got this part right. When i log the count every time it returns 0 although the items selected are true within array.
Any help please?