案例:
我问用户一个问题,答案是7
。
如何验证EditText
的条目是否为7,之后我想奖励1分。
//Question #1
//If Answer is equal to 7 than award One Point
int = score;
private EditText questionOneAnswer;
EditText text = (EditText) findViewById(R.id.Part2Question1);
String EditText = text.getText().toString().trim();
if(EditText.isEmpty() || EditText.length() == 0 ||
EditText.equals("7") || EditText == null)
{
//EditText is empty
}
答案 0 :(得分:0)
首先,您不能将预定义的类名用作变量名。其次是你对授予点的逻辑是不正确的。试试这个,
EditText text = (EditText) findViewById(R.id.Part2Question1);
String answer = text.getText().trim();
if(answer.equals("7"))
{
score++;
}
else{
// show some toast showing that answer is incorrect
}