Created
September 22, 2017 07:12
-
-
Save JaniKibichi/d0d6f98adc1c22117078a746a615247f to your computer and use it in GitHub Desktop.
MemoryGame Main Activity File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mjuaji.memorygame2308; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.TextView; | |
public class MainActivity extends Activity implements View.OnClickListener { | |
SharedPreferences prefs; | |
String dataName = "MyData"; | |
String intName = "MyInt"; | |
int defaultInt = 0; | |
int hiScore; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
//initialize two shared preference objects | |
prefs = getSharedPreferences(dataName, MODE_PRIVATE); | |
//load our high score or in unavailable, our default of 0 | |
hiScore = prefs.getInt(intName, defaultInt); | |
//make a reference to the hiScore text in the layout | |
TextView textHiScore = (TextView) findViewById(R.id.textHiScore); | |
//Display the hi score | |
textHiScore.setText("High Score: "+hiScore); | |
//Make a button from the button in our layout | |
Button button = (Button) findViewById(R.id.button); | |
//Make it listen for clicks | |
button.setOnClickListener(this); | |
} | |
@Override | |
public void onClick(View view) { | |
Intent i; | |
i = new Intent(this, GameActivity.class); | |
startActivity(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment