Quantcast
Channel: How do I use multiple lines in Kotlins when switch? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Dehodson for How do I use multiple lines in Kotlins when switch?

$
0
0

You need to surround your multiple lines of code in a block, like so:

when(version) {"anhorig" -> {        Log.d("TAG", "Anhorig")        subHeader.text = getString(R.string.sv_anhorig_ch1)    }"personal" ->        Log.d("TAG", "Personal")    else ->        Log.d("TAG", "Else")}

As for the type mismatch, the value of the when expression is equal to the last evaluated statement within the block. It seems like the expected value of this expression is Int, but your last statement is subHeader.text = getString(R.string.sv_anhorig_ch1) which is string.

You can read more in the Kotlin documentation for when expressions.


Viewing all articles
Browse latest Browse all 3

Trending Articles