I am learning android I tried following codeline but it\'s giving me error please give me suggestions, that how can I compare two edittext
\'s text.
Here's a solution that doesn't violate the DRY principle:
private static boolean allContain(final String value,
final EditText... editTexts)
{
for (EditText editText : editTexts) {
final String text = editText.getText().toString();
if (!text.equals(value)) {
return false;
}
}
return true;
}
You can use it as follows:
if (allContain("X", edt1, edt2, edt3, edt4)) {
// All EditTexts contain 'X'
}