我知道这应该很容易,但我真的不知道我做错了什么。
我想做这样的伪代码:
if EditText == "ed" {show.message "Hi"}
else {show.message "NOPE"}
//--[Boton Sumar 2]--
public void onBT_sumar2Click(View v) {
EditText e1 = (EditText)findViewById(R.id.ET_1);
EditText e2 = (EditText)findViewById(R.id.ET_2);
TextView t1 = (TextView)findViewById(R.id.TV_resultado);
if (e1.getText().equals("ed")){
Context context = getApplicationContext();
CharSequence text = ":V / hi :V /" ;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
else {
Context context = getApplicationContext();
CharSequence text = "NOPE";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
最佳答案
您应该将 e1
的值转换为字符串以供比较。
尝试:
if (e1.getText().toString().equals("ed")) { ...
关于java - Android 字符串与 EditText 字符串值的比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34660920/