0

I know there are many similar questions if not the same, but I cant get my head around it. I am wanting to get "mScore" which is a variable in my main activity to show on the end of a string which is in my results layout. This is to get their final score and show on my results page as "You Scored : mScore"

Here is some of my code

public int mScore = 0;


if (mButtonChoice1.getText() == mAnswer) {
                mScore = mScore + 1;
                updateScore(mScore);
            }


private void updateScore(int point){
    mScoreView.setText(""+mScore);
}

Again apologies for possible duplicate but I did not understand the other answers and am hoping i will understand better when it's specific for my situation. Only started learning java a week or 2 ago so i'm a bit slow.

LiamB645
  • 35
  • 6
  • 1
    this here: ***mButtonChoice1.getText() == mAnswer***... : gettext() returns a string and string should never be compared using == – ΦXocę 웃 Пepeúpa ツ Jun 06 '17 at 12:19
  • @ΦXocę웃Пepeúpaツ Okay thanks, i appreciate the help but how would i compare two string alternatively ? – LiamB645 Jun 06 '17 at 12:22
  • you can do ***mButtonChoice1.getText().equals(mAnswer)...*** but read the link of the dupplicated question... that is explaining pretty well what ust be done! – ΦXocę 웃 Пepeúpa ツ Jun 06 '17 at 12:23
  • Okay thanks however this was not my question, I want to add an int variable from one class to the end of a string variable in another class. @ΦXocę웃Пepeúpaツ – LiamB645 Jun 06 '17 at 12:27
  • Just concatenate the text with the score with `mScoreView.setText(mScoreView.getText()+ " " + mScore);`. @ΦXocę웃Пepeúpaツ is correct but this is not exactly the real problem ;). Do note that this will concatenate each time, so next click with have the previous score with it. Or simply `mScoreView.setText("You Scored : " + mScore)` – AxelH Jun 06 '17 at 12:47
  • Thanks @AxelH this is what i was looking for, problem solved :) – LiamB645 Jun 06 '17 at 12:50

0 Answers0