(LibGdx)TextField not receiving input

I have other UI using Scene2D, but the textfield wont take in any input. HEre’s how i initialize it.

txtUsername = new TextField("", mSkin);
 txtUsername.setMessageText("test");
mStage.addActor(txtUsername);

It is draw but I can’t input text. I looked through the docs; amI doing something wrong?

Did you call:

mStage.act(); //Updates everything in stage 

In your render method?

EDIT:

Dont forget to call:

mStage.draw(); //Draws everything in stage 

In your render method as well :wink:

yes

mStage.act(delta);
		mStage.draw();

Did you set the position of the textfield?

txtUsername.setPosition(x, y);

A quick google shows this as a potential solution: [icode] Gdx.input.setInputProcessor(mStage); [/icode]

CopyableCougar4

I didn’t, but that didn’t affect it.

For some reason I can’t do that in this class. My first screen switches to this one and this one doesn’t let me use that line of code. If I do, it doesn’t switch screens.

Have you tried putting in in the Screen’s [icode]show()[/icode]? (Assuming you’re using LibGDX’s Screen interface).

CopyableCougar4

It works :stuck_out_tongue: thanks

How do I save the input in to a string after “ENTER” is pressed? I’ve tried

String a = txtUsername.getText()

;

You can just use the TextFieldListener, monitor for Keys.ENTER, and then save into string and do what you like.