Boxy Laze Boxy Laze - 1 year ago 108
Java Question

Java - Libgdx : Check user's input in a textfield?

My if..else statement:

} else if(réponse.getText().equals("riviere")){
game.setScreen(new Stage1(game));
else if(!réponse.getText().equals("riviere")){
ecrireLeTexte = true;

I created a textfield and then straight away check what's in it but I'm afraid the user can't type anything before the textfield check's...

so how to check the user's input after it's typing ?

Answer Source

You can put your check in your render method so it will be called each frame or set TextFieldListener to your TextField to listen for changes.

réponse.setTextFieldListener(new TextField.TextFieldListener() {
    public void keyTyped(TextField textField, char c) {
        //Here you can compare the text

Also remember to set your Stage as InputProcessor fe. Gdx.input.setInputProcessor(stage);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download