【发布时间】:2020-03-30 08:43:05
【问题描述】:
我正在开发一项自我评估功能,这将使人们知道他们是否有感染电晕的风险,从而建议他们是否接受检测。我创建了许多单选按钮,让患者检查不同的症状,为每个单击的单选按钮分配,该单选按钮应该与其他值相加,以便找到一个分数,我们可以在该分数上知道患者是否应该是否继续进行covid-19测试。我需要帮助来修复我的代码,以便能够读取和添加每个单选按钮的所有值。这是我的代码。
if (view is RadioButton) {
// Is the button now checked?
val checked = view.isChecked
// Check which radio button was clicked
when (view.getId()) {
R.id.yes_1 ->
if (checked) {
val yes1= 1
Toast.makeText(this, "Yes 1", Toast.LENGTH_LONG).show()
}
R.id.no_1 ->
if (checked){
val no1=0
Toast.makeText(this, " No 1", Toast.LENGTH_SHORT).show()
}
R.id.yes_2 ->
if (checked) {
val yes2= 1
Toast.makeText(this, "Yes 2", Toast.LENGTH_LONG).show()
}
R.id.no_2 ->
if (checked) {
val no2= 0
Toast.makeText(this, "No 2", Toast.LENGTH_SHORT).show()
}
R.id.yes_3 ->
if (checked) {
val yes3=1
Toast.makeText(this, "Yes 3", Toast.LENGTH_LONG).show()
}
R.id.no_3 ->
if (checked) {
val no3=0
Toast.makeText(this, "No 3", Toast.LENGTH_SHORT).show()
}
R.id.yes_4 ->
if (checked) {
val yes4=1
Toast.makeText(this, "Yes 4", Toast.LENGTH_LONG).show()
}
R.id.no_4 ->
if (checked) {
val no4=0
Toast.makeText(this, "No 4", Toast.LENGTH_SHORT).show()
}
R.id.yes_5 ->
if (checked) {
val yes5=5
Toast.makeText(this, "Yes 5", Toast.LENGTH_LONG).show()
}
R.id.no_5 ->
if (checked) {
val no5=0
Toast.makeText(this, "No 5", Toast.LENGTH_SHORT).show()
}
R.id.yes_6 ->
if (checked) {
val yes6=5
Toast.makeText(this, "Yes 6", Toast.LENGTH_LONG).show()
}
R.id.no_6 ->
if (checked) {
val no6=0
Toast.makeText(this, "No 6", Toast.LENGTH_SHORT).show()
}
}
val assesment_point= yes1 + n01 + yes2 + no2 +yes3 + no3 + yes4 + no4 + yes5 + no5 + yes6 + no6
}
}
【问题讨论】:
标签: android-studio kotlin android-activity switch-statement