Hashey100
Hashey100

Reputation: 984

Using if-statement to compare strings

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

Upvotes: 0

Views: 195

Answers (1)

Kaediil
Kaediil

Reputation: 5535

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.

Upvotes: 2

Related Questions