简单分支
text_show.text = if (is_odd == true) {
"凉风有信"
} else {
"秋月无边"
}
多路分支
private var count: Int = 0
btn_set_for.setOnClickListener { v ->
when (count) {
0 -> text_multi_show.text = "凉风有信"
1 -> text_multi_show.text = "秋月无边"
else -> text_multi_show.text = "好诗"
}
}
private var count: Int = 0
btn_multi.setOnClickListener { v ->
text_multi_show.text = when (count) {
0 -> "好好学习"
1 -> "天天向上"
else -> "好诗"
}
}
//引入变量判断
private var odd: Int = 0
private var even: Int = 1
btn_variable.setOnClickListener { v ->
text_multi_show.text = when (count) {
odd -> "好好学习"
even -> "天天向上"
else -> "好诗"
}
}
网友评论