I'm making a game a game kind of like a trivia game witha separate class and xml for each question I need it to keep score on my main activity. All the activitys xml shows its players name so I decided since only two things Need to be remembered sharedpreferences is perfect I've gotten the usernames to stay and not cause any force close thanks to this website. But for a few hours I've been trying figure out how to make my textview go from 0 to 1 and then from 1 to 2 and so on I have a class and xml that says wrong and one that says right. so inside those classes I want the to go
if(username1==displayedname.getText.toString ())
PeepsScore.Userscore1+1
(basically) Sorry for the syntax but without my notes I'm very bad at this I'm teaching myself via Google and YouTube. Basically I set the textxiew in that class to blank and my java puts in whatever there name is so I am looking for an if statement that's realizes that textview is the same as the shared preference username1. which I believe I've done. so I just need to know how to add a point. I also already have userscore1 stored in shared preferences. If there's another idea completely different than an if statement that's fine as well any example code links hints I will take anything at this point Edit(
ok i changed it to the putint() method and here it is
int zero=0;
SharedPreferences peepsScores= PreferenceManager.getDefaultSharedPreferences(GamePlayFirst.this);
SharedPreferences.Editor editor =peepsScores.edit();
editor.putInt("userScore1", zero);
editor.putInt("userScore2", zero);
editor.putInt("userScore3", zero);
editor.putInt("userScore4", zero);
editor.putInt("userScore5", zero);
editor.putInt("userScore6", zero);
editor.putInt("userScore7", zero);
editor.putInt("userScore8", zero);
editor.commit();
SharedPreferences peepsScores = PreferenceManager.getDefaultSharedPreferences(this);
//tryed this
int userScore1 = peepsScores.getInt("userScore1","u");
//tryed this
userScore2 = peepsScores.getInt("userScore2","0");
//and tryed this
String userScore3 = peepsScores.getInt("userScore3","0");
String userScore4 = peepsScores.getInt("userScore4","0");
String userScore5 = peepsScores.getInt("userScore5","0");
String userScore6 = peepsScores.getInt("userScore6","0");
String userScore7 = peepsScores.getInt("userScore7","0");
String userScore8 = peepsScores.getInt("userScore8","0");
the get int method is underlined no matter what random things i change and then if i delete the firts line of the recieving class peepScore is underlined im been on android dev webiste this website and all over google everything says its as easy as getInt what am i doing wrong
Ill try to figure out adding later i guess when i finaly get this im posting this for all newbs like me to see lol
==to compare strings, it wont work. UseString.equals(String). Aside from that I don't really understand your question.