主页面写了好多代码和函数,显得很乱,想把写的一些函数集中放在另一个文件,但是好像写的函数关联太多东西,单独调走生成无数警告😅,不知道是不是我的方法不对(就是创建一个新的.kt文件,然后把fun丢进去就完事),源代码网址:https://github.com/UnaAtadura-Eris/MedicaRecord
想要移动的代码具体如下:
private fun faRe() {
showQuestion(questions_faRe[currentQuestionIndex])
nextButton.setOnClickListener {
val currentQuestion = questions_faRe[currentQuestionIndex]
if (currentQuestion.type == QuestionType.SINGLE_CHOICE) {
val selectedOptionId = optionsRadioGroup.checkedRadioButtonId
val selectedIndex =
optionsRadioGroup.indexOfChild(findViewById<RadioButton>(selectedOptionId))
if (selectedIndex == -1) {
// 提示用户选择一个选项
currentQuestionIndex -= 1
Toast.makeText(this, "请选择一个选项", Toast.LENGTH_SHORT).show()
} else{
// 对选中的单选题选项进行处理
// 例如,根据选中的选项执行相应的操作
when (val selectedOption = currentQuestion.options[selectedIndex]) {
"发热程度详解" -> {
val detailedExplanation = faRechengDuxiangJie
detailedExplanationTextView.text = detailedExplanation
currentQuestionIndex -= 1
}
"发热的特点详解" -> {
val detailedExplanation = reXingxiangJie
detailedExplanationTextView.text = detailedExplanation
currentQuestionIndex -= 1
}
"痰的颜色性质详解" -> {
val detailedExplanation = tanYanseXiangjie
detailedExplanationTextView.text = detailedExplanation
currentQuestionIndex -= 1
}
"痰量及咯出详解" -> {
val detailedExplanation = tanLiangxiangJie
detailedExplanationTextView.text = detailedExplanation
currentQuestionIndex -= 1
}
"皮疹特点详解" -> {
val detailedExplanation = piZhenxiangJie
detailedExplanationTextView.text = detailedExplanation
currentQuestionIndex -= 1
}
else -> {
// 这里可以根据需求将 answerToRecord 存储到适当的数据结构中
resultList.add("$selectedOption,")
val resultString = resultList.joinToString("")
answerToRecordTextView.text = resultString
}
}
}
} else if (currentQuestion.type == QuestionType.MULTI_CHOICE) {
val selectedOptions = mutableListOf<String>()
val unselectedOptions = mutableListOf<String>()
for (i in 0 until optionsRadioGroup.childCount) {
val checkBox = optionsRadioGroup.getChildAt(i) as CheckBox
val option = currentQuestion.options[i]
if (checkBox.isChecked) {
selectedOptions.add(option)
} else {
unselectedOptions.add(option)
}
}
val selectedOptionsText = if (selectedOptions.isNotEmpty()) {
"有" + selectedOptions.joinToString("、")
} else {
""
}
val unselectedOptionsText = if (unselectedOptions.isNotEmpty()) {
"无" + unselectedOptions.joinToString("、")
} else {
""
}
val answerToRecord = "$selectedOptionsText,$unselectedOptionsText。"
// 这里可以根据需求将 answerToRecord 存储到适当的数据结构中
// answerToRecordTextView.append(answerToRecord)
resultList.add(answerToRecord)
val resultString = resultList.joinToString("")
answerToRecordTextView.text = resultString
// 对选中的多选题选项进行处理
// 例如,根据选中的选项执行相应的操作
for (selectedOption in selectedOptions) {
when (selectedOption) {
"咳痰" -> {
val newquestions = listOf(
Question(
"痰的颜色性质",
listOf(
"白黏痰",
"黄脓痰",
"绿色痰",
"浓臭痰,痰液分4层",
"浓臭痰,痰液分3层",
"颜色不详",
"痰的颜色性质详解"
),
QuestionType.SINGLE_CHOICE,
emptyList()
),
Question(
"痰的量多多少及是否易咯出",
listOf("量多易咯", "量少难咯", "痰量及咯出详解"),
QuestionType.SINGLE_CHOICE,
emptyList()
)
)
questions_faRe = questions_faRe.plus(newquestions)
}
"皮疹" -> {
val newquestions = listOf(
Question(
"皮疹特点",
listOf(
"发热1天后出疹",
"发热5天至1周出疹",
"发热伴有环形红斑或结节性红斑",
"皮疹特点详解"
),
QuestionType.SINGLE_CHOICE,
emptyList()
)
)
questions_faRe = questions_faRe.plus(newquestions)
}
else -> {
// currentQuestionIndex += 0
// answerToRecordTextView.append("雷狼龙3")
}
}
}
}
currentQuestionIndex++
if (currentQuestionIndex < questions_faRe.size) {
showQuestion(questions_faRe[currentQuestionIndex])
} else {
nextButton.setText("结束")
nextButton.isEnabled = false
}
}
resetButton.setOnClickListener {
resetPage(questions_faRe)
}
returnButton.setOnClickListener {
returnPage(questions_faRe)
}
}