Как проверять и вписывать значения в Java Android Studio?
Вот я написал но оно не работает?
public void onMyStart(View view) {
EditText editText = findViewById(R.id.editText);
String value = editText.getText().toString();
TextView textTrue = findViewById(R.id.textIQ);
//Strings true
String John = "John Dau";
String Tek = "Tek Solem";
if (value == John) {
textTrue.setText("160 iq");
}
if (value == Tek) {
textTrue.setText("140 iq");
}
else {
Random rnd = new Random()
int render = rnd.nextInt(50)+1;
textTrue.setText(render);
}
}
Ответы (1 шт):
Автор решения: Arty Morris
→ Ссылка
К строкам нельзя применять знак ==. Для сравнения строк необходимо использовать equals. Вам нужно написать так:
if (value.equals("John Dau")) {
textTrue.setText("160 iq");
}
или
if (value.equals(John)) {
textTrue.setText("160 iq");
}