// 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("It is certain."); predObject.addPrediction("It is decidedly so."); predObject.addPrediction("Without a doubt."); predObject.addPrediction("Yes--definitely."); predObject.addPrediction("You may rely on it."); predObject.addPrediction("As I see it, yes."); predObject.addPrediction("Most likely."); predObject.addPrediction("Outlook good."); predObject.addPrediction("Yes."); predObject.addPrediction("Signs point to yes."); predObject.addPrediction("Reply hazy, try again."); predObject.addPrediction("Ask again later."); predObject.addPrediction("Better not tell you now."); predObject.addPrediction("Cannot predict now."); predObject.addPrediction("Concentrate and ask again."); predObject.addPrediction("Don\'t count on it."); predObject.addPrediction("My reply is no."); predObject.addPrediction("My sources say no."); predObject.addPrediction("Outlook not so good."); predObject.addPrediction("Very doubtful."); } // 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( )); } }