我正在使用Eclipse运行以下代码。如果语句在比较两个字符串时不运行Android Eclipse
我想比较我在TextView中输入的内容到 我在我的字符串数组中有什么。我甚至还设置了 TextViews文本和字符串数组值,我在012语句运行之前将 与之相比较。我觉得好像 我错过了一些简单的东西,所以也许有人可以指出 我在正确的方向。下面是一些示例代码:
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);
这是当我选择我的设备上提交按钮的代码永远不会运行在那里我比较值
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();
}
}
。 我试图在那里添加一个其他的东西,这就是我想要的东西,它总是返回不平等,所以我不知道我在这里失踪了什么。
感谢
请搜索SO。 http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – pmac89