Kotlin when with multiple values not working when value is an android view

Solution 1:

You're missing the other is:

fun applyTemplateViewStyles(view: View) {
    when(view) {
        is EditText, is TextView -> {
            println("view is either EditText or TextView")
        }
        else -> {
            println("view is something else")
        }
    }
}

Solution 2:

You can do this, you just didn't get the syntax right. The following works for handling multiple types under one branch of when:

when(view) {
    is EditText, is TextView -> {
        ....
    }
}

Solution 3:

In case of multiple text option handling you can use comma

when(option) { //option is string
    "type A","type B" -> {
        ....
    }
}

Solution 4:

Use comma-separated to handle multiple options for the same execution.

{ 
view ->
   when(view.id) {
       homeView.tv_new_dealer_rank_to_achieve.id,
       homeView.tv_sales_rank_to_achieve.id,
       homeView.tv_payment_rank_to_achieve.id,
       homeView.tv_bill_dealer_rank_to_achieve.id -> {
           homePresenter.reDirectToFragment(10)
       }
    }
}