Reputation: 91
I want to compare a xml string with a string from an edittext oder button. first I set the text of the button:
button1.setText(getString(R.string.okey));
and now I want to check if the text from the button is the same as R.string.okey from the xml file. Like this I can leave out a new variable.
Is it possible to check if the strings are the same with something like this?
if (button1.getText().toString().equals(getString(R.string.okey))){
}
But that doesn't work for me.
Thank you in advance.
Upvotes: 0
Views: 58
Reputation: 19243
this must work, its just to simple. you must change somehow text on button or maybe getString
returns different text (Locale
changed?). use logging or debugger to check what is button1.getText().toString()
and getString(R.string.okey)
at the moment of comparison (equals
call)
boolean areEqual = button1.getText().toString().equals(getString(R.string.okey));
Log.i("justChecking", "getString:" + getString(R.string.okey) +
", button1.getText:" + button1.getText().toString() +
", are equal:" + areEqual);
if (areEqual){
}
How to Write and View Logs with Logcat
Upvotes: 1
Reputation: 769
Store them in variables
String a = button1.getText()+"";
String b = getString(R.string.str)+"";
if(a.equals(b)){ }
Upvotes: 1