Questions with pass or fail

Hi I am new to kotlin and have come across few issues, please could someone support me.

I have trying to create a app where user get asked 10 question with Pass or Fail option.

I have following coding in Button_Activity.

package com.example.myapplication

import android.os.Bundle
import android.view.View
import android.widget.RadioButton
import android.widget.RadioGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_button.*

class ButtonActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_button)

    // Get radio group selected item using on checked change listener
    radiogrouppassfail.setOnCheckedChangeListener(
        RadioGroup.OnCheckedChangeListener { group, checkedId ->
            val radio: RadioButton = findViewById(checkedId)
            Toast.makeText(
                applicationContext, " On checked change : ${radio.text}",
                Toast.LENGTH_SHORT
            ).show()
        })


    // Get radio group selected status and text using button click event
    button_apply_passfail.setOnClickListener {
        // Get the checked radio button id from radio group
        var id: Int = radiogrouppassfail.checkedRadioButtonId
        if (id != -1) { // If any radio button checked from radio group
            // Get the instance of radio button using id
            val radio: RadioButton = findViewById(id)
            Toast.makeText(
                applicationContext, "On button click : ${radio.text}",
                Toast.LENGTH_SHORT
            ).show()
        } else {
            // If no radio button checked in this radio group
            Toast.makeText(
                applicationContext, "On button click : nothing selected",
                Toast.LENGTH_SHORT
            ).show()
        }
    }
}

// Get the selected radio button text using radio button on click listener
fun checkButtonPassFail(view: View) {
    // Get the clicked radio button instance
    val radio: RadioButton = findViewById(radiogrouppassfail.checkedRadioButtonId)
    Toast.makeText(
        applicationContext, "On click : ${radio.text}",
        Toast.LENGTH_SHORT
    ).show()
}

}

I have following code in Layout

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android
xmlns:app=“http://schemas.android.com/apk/res-auto
xmlns:tools=“http://schemas.android.com/tools
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_centerInParent=“false”
android:layout_centerHorizontal=“false”
android:layout_centerVertical=“false”
android:background=“@color/colorPrimary”
tools:context=“.MainActivity”>

<TextView
    android:id="@+id/Selectiontextview"
    android:layout_width="326dp"
    android:layout_height="25dp"
    android:gravity="center"
    android:text="AM Shift Walk Around Check."
    android:textColor="@color/colorPrimaryDark"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.493"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.006" />

<TextView
    android:id="@+id/textquestionview"
    android:layout_width="385dp"
    android:layout_height="146dp"
    android:layout_marginStart="14dp"
    android:layout_marginLeft="14dp"
    android:layout_marginTop="12dp"
    android:layout_marginEnd="14dp"
    android:layout_marginRight="14dp"
    android:text="TextView hb 09/03"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/Selectiontextview" />

<RadioGroup
    android:id="@+id/radiogrouppassfail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="156dp"
    android:layout_marginLeft="156dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="156dp"
    android:layout_marginRight="156dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textquestionview">

    <RadioButton
        android:id="@+id/Pass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:onClick="checkButtonPassFail"
        android:text="Pass"
        android:textSize="30sp" />

    <RadioButton
        android:id="@+id/Fail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="checkButtonPassFail"
        android:text="Fail"
        android:textSize="30sp" />

</RadioGroup>

<TextView
    android:id="@+id/text_view_selected"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="102dp"
    android:layout_marginLeft="102dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="102dp"
    android:layout_marginRight="102dp"
    android:text="Your Selection: "
    android:textSize="30sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/radiogrouppassfail"
    />

<Button
    android:id="@+id/button_apply_passfail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="162dp"
    android:layout_marginLeft="162dp"
    android:layout_marginTop="220dp"
    android:layout_marginEnd="162dp"
    android:layout_marginRight="162dp"
    android:text="Apply"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/text_view_selected"
    />

</androidx.constraintlayout.widget.ConstraintLayout>

I need help with following

  1. How to get question in Text view box?
  2. How to summarise all question with answers and summit to email?

I have look at may video on yourtube but none is been help full.

Please could i request for some support.

Is there no one who can assist me with above query.

This forum is for specific kotlin questions only.
If you like to “learn” kotlin and android,
you get more help in https://stackoverflow.com/

Hi Thank for the response.

I am programming in Kotlin Android Studio, Hence the reason for me asking this question.

I am reading up book and youtube video but no found what i am trying to do.

Regards

Lesson 3 (App Navigation) of this course builds an Android trivia quiz app:

That may help with your first question.