I am trying to do something but I don't know how to do it. Let's see if someone can help me.
I have a EditText
and my intention is that depending on what you write in it, clicking on my Boton
will execute one method and another.
For example, that the correct words are only: " Hello ", " Salut " and Hello ", if you write one of those three words and click on btn1
it, the first method is executed. But if you write any other word or none, it is executed the second method.Is this possible?
I leave here what I have been able to do with the code.
public class Main5Activity extends AppCompatActivity {
EditText text1;
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main5);
text1 = (EditText) findViewById(R.id.text1);
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// si la palabra es correcta:
Toast.makeText(Main5Activity.this, "Correcto!", Toast.LENGTH_LONG).show();
// si la palabra no es correcta o no se ha escrito nada:
Toast.makeText(Main5Activity.this, "No es correcto", Toast.LENGTH_LONG).show();
}
});
}
}