0

I'm building a quiz app in Android Studio. One of my questions has an EditText to write in the answer. 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.

Any help is greatly appreciated. I am a new coder so I could really use a hand!

Ms_Lese
  • 13
  • 5

1 Answers1

0

You can't call isChecked() on an EditText. To recognise the right answer you would simply have to compare the user's input in the EditText with the correct answer. I.e.

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.

Chris Dueck
  • 682
  • 8
  • 17
  • Yes, that is what I am talking about. I just have to figure out how to incorporate it into my code. My xml is good, I've just been having trouble with my java. I will post my java above if you don't mind looking at it. – Ms_Lese Mar 11 '18 at 01:04
  • Go ahead. I'll have a look. – Chris Dueck Mar 12 '18 at 00:23