// Magic8Ball2 Example // Source code file: MainActivity.kt package it372.sjost.magic8ball2 import android.os.Bundle import android.util.Log import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { // Declare instance variables for widget objects. // ? means that the object might be null var txtPred : TextView? = null var predObj : Prediction? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Instantiate the TextView widget object txtPred = findViewById(R.id.txt_prediction) // Instantiate the Magic8Ball Prediction object predObj = Prediction( ) // Set onClick listener for textview. // !! means "I take responsibility to make sure // that the objects are non-null. txtPred!!.setOnClickListener { predObj!!.chooseRandomPrediction( ) txtPred!!.setText(predObj!!.pred) } } }