I've got a problem with clicks counter, when I'm clicking on the Button the number of clicks doesn't appear but when I beat my "high score", the score changes. How am I supposed to make appear the number of clicks while I'm clicking on the Button? I also want my new scores to be saved.
Here is my code:
public class newgame extends Activity {
int clicks = 0;
TextView textCount;
Button buttonCount;
int guessCount =0;
View view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_newgame);
final int oldscore = getSharedPreferences("myPrefs", MODE_PRIVATE).getInt("highscore", 0);
final TextView textView = (TextView) findViewById(R.id.topScoreView);
buttonCount = (Button) findViewById(R.id.button);
buttonCount.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
clicks++;
textView.setText("High Score: " + oldscore);
}
public void takeTheGuess(View view) {
clicks++;
textView.setText("Clicks:" + clicks);
}
});
final TextView textic = (TextView) findViewById(R.id.textView2);
CountDownTimer Count = new CountDownTimer(15000, 1000) {
public void onTick(long millisUntilFinished) {
int seconds = (int) ((millisUntilFinished / 1000));
textic.setText("Time Left: " + millisUntilFinished / 1000);
}
public void onFinish() {
textic.setText("Time's Up!");
buttonCount.setEnabled(false);
if (clicks > oldscore)
getSharedPreferences("myPrefs", MODE_PRIVATE).edit().putInt("highscore", clicks).commit();
}
};
Count.start();
}
0 comments:
Post a Comment