I am using Eclipse to run the following code.
I am trying to compare what I'm entering in the TextView to what I have in my string array. I even went as far as to set the TextViews text and the string arrays value that I'm comparing to the same thing before the if statement runs. I feel as though I'm missing something simple here so maybe someone could point me in the right direction. Here is some sample code:
public class StartActivity extends Activity {
String[] keyWord = {"cow", "hour", "trial", "active", "purpose", "cat", "route", "laser", "fresh", "success" };
Random randWord = new Random();
int secretWord = randWord.nextInt(10);
This is where I am comparing the values
public void SubmitClick(View v){
TextView TV = (TextView)findViewById(R.id.txtAnswer);
keyWord[secretWord] = "the";
TV.setText("the");
if(keyWord[secretWord] == TV.getText().toString()){
Toast.makeText(getApplicationContext(), "Correct guess!",
Toast.LENGTH_LONG).show();
}
}
When I select the submit button on my device the code never runs. I tried adding an else in there which is what I wan't and it always comes back as not equal so I have no idea what I'm missing here.
Thanks