Android If语句代码
好的,我正在尝试制作一个应用程序,它只接受任何文本中的一个单词。我正在使用edittext让用户输入文本并按下按钮,让他们用您的不正确或正确的单词干杯 问题是当我使用if语句时,我无法让它工作。有人能确定问题吗?这是我的代码Android If语句代码,android,eclipse,Android,Eclipse,好的,我正在尝试制作一个应用程序,它只接受任何文本中的一个单词。我正在使用edittext让用户输入文本并按下按钮,让他们用您的不正确或正确的单词干杯 问题是当我使用if语句时,我无法让它工作。有人能确定问题吗?这是我的代码 public class IfActivity extends Activity { Button GO; EditText TEXT; /** Called when the activity is first created. */ @Override public
public class IfActivity extends Activity {
Button GO;
EditText TEXT;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GO = (Button) findViewById(R.id.go);
TEXT = (EditText) findViewById(R.id.Textin);
GO.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
if ("hello".equals(TEXT)) {
Toast andEggs = Toast.makeText(IfActivity.this,
"PASSWORD IS CORRECT", Toast.LENGTH_SHORT);
andEggs.show();
} else {
Toast andEggs = Toast.makeText(IfActivity.this,
"PASSWORD IS INCORRECT", Toast.LENGTH_SHORT);
andEggs.show();
}
}
});
}
}使用以下方法:
if("hello".equals((findViewById(R.id.Textin)).getText().toString())) { // show toast}
使用以下命令:
if("hello".equals((findViewById(R.id.Textin)).getText().toString())) { // show toast}
文本
不是字符串。它是EditText的一个参考变量
if (TEXT.getText().toString().equals("hello"))
{
}
文本
不是字符串。它是EditText的一个参考变量
if (TEXT.getText().toString().equals("hello"))
{
}
使用以下命令:
public void onClick(View arg0) {
// TODO Auto-generated method stub
String tempTxt = ((EditText) findViewById(R.id.Textin)).getText().toString();
if ("hello".equals(tempTxt )) {
Toast andEggs = Toast.makeText(IfActivity.this,"PASSWORD IS CORRECT",Toast.LENGTH_SHORT);
andEggs.show();
}
else{
Toast andEggs = Toast.makeText(IfActivity.this,"PASSWORD IS INCORRECT",Toast.LENGTH_SHORT);
andEggs.show();
}
}
使用以下命令:
public void onClick(View arg0) {
// TODO Auto-generated method stub
String tempTxt = ((EditText) findViewById(R.id.Textin)).getText().toString();
if ("hello".equals(tempTxt )) {
Toast andEggs = Toast.makeText(IfActivity.this,"PASSWORD IS CORRECT",Toast.LENGTH_SHORT);
andEggs.show();
}
else{
Toast andEggs = Toast.makeText(IfActivity.this,"PASSWORD IS INCORRECT",Toast.LENGTH_SHORT);
andEggs.show();
}
}
“我不能让它工作”到底是什么意思?“我不能让它工作”到底是什么意思?谢谢,老兄,我知道我错过了一些东西,只是一个手指都插不上。再次感谢汉克,老兄,我知道我错过了一些东西,只是一个手指都插不上