简体   繁体   English

Android Studio中的EditText Java代码

[英]EditText Java Code in Android Studio

I'm building a quiz app in Android Studio. 我正在Android Studio中构建测验应用程序。 One of my questions has an EditText to write in the answer. 我的问题之一是在答案中写一个EditText。 I am stuck on how to determine the score for this answer. 我被困在如何确定这个答案的分数上。 Is it a boolean or a string? 是布尔值还是字符串? Here is what I have: 这是我所拥有的:

    EditText q4 = (EditText)findViewById(R.id.answer4_Wakanda);
    Boolean q4RightAnswer = q4.isChecked();

I know this is wrong. 我知道这是错的。 I had a string and changed it to a boolean, which is where I got stuck. 我有一个字符串,并将其更改为布尔值,这就是我遇到的问题。 It's possible that the whole thing is wrong. 整个事情很可能是错误的。 I just want my app to recognize the right answer, in order to give it 1 point. 我只是想让我的应用识别正确的答案,以便给它1分。

Any help is greatly appreciated. 任何帮助是极大的赞赏。 I am a new coder so I could really use a hand! 我是一名新编码员,所以我真的可以动手!

You can't call isChecked() on an EditText. 您不能在EditText上调用isChecked() To recognise the right answer you would simply have to compare the user's input in the EditText with the correct answer. 要识别正确的答案,您只需要将用户在EditText中的输入与正确的答案进行比较即可。 Ie

String userAns = q4.getText().toString();
if (userAns.equals(correctAns)) {
    // correct, add 1 point
}
else {
    // incorrect, do something else
}

I hope this is what you are looking for, if not I would need some further clarification on what the issue is, or perhaps a larger portion of your code. 我希望这是您正在寻找的东西,如果不是这样,我将需要进一步澄清问题所在,或者可能需要更多代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM