Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val submitButton = findViewById<Button>(R.id.submit_button)
- submitButton.setOnClickListener {
- showAlertDialog()
- }
- private fun showAlertDialog() {
- AlertDialog.Builder(this)
- .setTitle("Submit Confirmation")
- .setMessage("Are you sure you want to submit?")
- .setPositiveButton("Yes") { dialog, which ->
- dialog.dismiss()
- Toast.makeText(this, "Submission Confirmed", Toast.LENGTH_SHORT).show()
- calcres()
- }
- .setNegativeButton("No") { dialog, which ->
- dialog.dismiss()
- }
- .show()
- }
- private fun calcres() {
- val radioGroupIds = arrayOf(
- R.id.RG1, R.id.RG2, R.id.RG3, R.id.RG4, R.id.RG5,
- R.id.RG6, R.id.RG7, R.id.RG8, R.id.RG9, R.id.RG10,
- R.id.RG11, R.id.RG12 // Add IDs for the new RadioGroups
- )
- val correctans = mutableListOf(
- "True", "False", "True", "False", "True",
- "False", "True", "False", "True", "False",
- "True", "False" // Add the correct answers for the new questions
- )
- val urans = mutableListOf<String>()
- var score = 0
- radioGroupIds.forEachIndexed { index, radioGroupId ->
- val radioGroup = findViewById<RadioGroup>(radioGroupId)
- val selectedRadioButtonId = radioGroup.checkedRadioButtonId
- if (selectedRadioButtonId != -1) {
- val radioButton = findViewById<RadioButton>(selectedRadioButtonId)
- val selectedText = radioButton.text.toString()
- urans.add(selectedText)
- if (selectedText == correctans[index]) {
- score++
- }
- } else {
- urans.add("Not Answered")
- }
- }
- tempScore = score
- checkPermissionsAndShowNotification(score)
- val intent = Intent(this, MainActivity2::class.java).apply {
- putExtra("score", score)
- putStringArrayListExtra("ans", ArrayList(urans))
- }
- startActivity(intent)
- }
- #ON NEXT PAGE
- val getans:ArrayList<String>?=intent.getStringArrayListExtra("ans")
- val answersText = getans?.joinToString(separator = "\n") ?: "No answers provided"
- val score=intent.getIntExtra("score",0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement