Advertisement
Shiyan12

MainActivity.java

Jul 19th, 2021
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package com.example.youdothemath;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.Button;
  11. import android.widget.TextView;
  12.  
  13.  
  14. public class MainActivity extends AppCompatActivity implements OnClickListener {
  15.  
  16.     private Button MathButton;
  17.     private Button MazeButton;
  18.     private TextView WelcomeText;
  19.     private TextView Result1Text;
  20.     private TextView Result2Text;
  21.     private TextView MathText;
  22.     private TextView MazeText;
  23.  
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_main);
  28.         MathButton = findViewById(R.id.math_icon);
  29.         MazeButton = findViewById(R.id.maze_icon);
  30.         WelcomeText = findViewById(R.id.welcome);
  31.         Result1Text = findViewById(R.id.result1);
  32.         Result2Text = findViewById(R.id.result2);
  33.         MathText = findViewById(R.id.math_txt);
  34.         MazeText = findViewById(R.id.maze_txt);
  35.         MathButton.setOnClickListener(this);
  36.  
  37.         SharedPreferences scorePrefs = getSharedPreferences(PlayGame.GAME_PREFS, 0);
  38.         String[] savedScores = scorePrefs.getString("highScores", "").split("\\|");
  39.         String BestScore = savedScores[0];
  40.         Result1Text.setText(BestScore);
  41.     }
  42.  
  43.     public void onClick(View view) {
  44.         if (view.getId() == R.id.math_icon) {
  45.             Intent intent = new Intent(this, Menu.class);
  46.             startActivity(intent);
  47.         }
  48.     }
  49.  
  50. }
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement