// Magic8Ball Example // Source code file: MainActivity.java // When linear layout is clicked, display randomly one // of the 20 Magic8Ball predictions. package it372.ssmith.magic8ball; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; 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); setContentView(R.layout.activity_main); // 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( )); } }