// Magic8Ball Example // Source code file: MainActivity.java package it372.ssmith.magic8ball; import android.os.Bundle; import android.view.View; import android.widget.TextView; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class MainActivity extends AppCompatActivity { // Make predObject an instance variable so // that it can be used in both of the onCreate // and showRandomPrediction methods. private Prediction predObject = new Prediction( ); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); // Load predictions into the Prediction object. predObject.addPrediction(getString(R.string.pred1)); predObject.addPrediction(getString(R.string.pred2)); predObject.addPrediction(getString(R.string.pred3)); predObject.addPrediction(getString(R.string.pred4)); predObject.addPrediction(getString(R.string.pred5)); predObject.addPrediction(getString(R.string.pred6)); predObject.addPrediction(getString(R.string.pred7)); predObject.addPrediction(getString(R.string.pred8)); predObject.addPrediction(getString(R.string.pred9)); predObject.addPrediction(getString(R.string.pred10)); predObject.addPrediction(getString(R.string.pred11)); predObject.addPrediction(getString(R.string.pred12)); predObject.addPrediction(getString(R.string.pred13)); predObject.addPrediction(getString(R.string.pred14)); predObject.addPrediction(getString(R.string.pred15)); predObject.addPrediction(getString(R.string.pred16)); predObject.addPrediction(getString(R.string.pred17)); predObject.addPrediction(getString(R.string.pred18)); predObject.addPrediction(getString(R.string.pred19)); predObject.addPrediction(getString(R.string.pred20)); } // Click event handler for the linear layout. // Show random prediction when layout is clicked. public void showRandomPrediction(View view) { TextView tv = findViewById(R.id.txt_pred); tv.setText(predObject.getPrediction( )); } }