0

How can i get my code to compare the string inputted by the user - so lets say the user presses keypad_1 , i then want to press the keypad_hash button and display incorrect to the user - The issue is when i press keypad_hash nothing happens thank you

1 Answer 1

2

This line:

if ("1".equals(answer.getText()))

should be:

if ("1".equals(answer.getText().toString()))

getText returns a CharSequence, not a string. From the documentation on String:

public boolean equals(Object anObject)

Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.