Set Focus to newTextField after calling it.

Is there a way to set the focus to a text field right after calling it? Or a way to call the textFiel with the focus already set on it?

I know I can use “native.setKeyboardFocus()” to set the focus, but unfortunately this won’t work if I do it right after calling the textField. The only way around I know is by using a timer or by clicking on the text field after calling it.

Any ideas?

https://docs.coronalabs.com/api/library/native/setKeyboardFocus.html

I’m not sure what you mean by ‘calling it’.  Do you mean after creating a newTextField()?

Some sample code of what you are trying to do might help us.

The only way of setting focus is what roaminggamer has mentioned above.

You could add a timer within the show() method of around 50ms and then call the native.setKeyboardFocus() function passing in your textField.

Hi guys, thanks a lot for the answers :slight_smile:
 

Yeah, that’s what I am doing right now. I create a newTextField() and right after I use a timer to set the Focus. My question is if there is a way to do the same thing but without using a timer.

You don’t need to use a timer.

This will work fine:

local field = native.newTextField( ... ) native.setKeyboardFocus( field )

https://docs.coronalabs.com/api/library/native/setKeyboardFocus.html

I’m not sure what you mean by ‘calling it’.  Do you mean after creating a newTextField()?

Some sample code of what you are trying to do might help us.

The only way of setting focus is what roaminggamer has mentioned above.

You could add a timer within the show() method of around 50ms and then call the native.setKeyboardFocus() function passing in your textField.

Hi guys, thanks a lot for the answers :slight_smile:
 

Yeah, that’s what I am doing right now. I create a newTextField() and right after I use a timer to set the Focus. My question is if there is a way to do the same thing but without using a timer.

You don’t need to use a timer.

This will work fine:

local field = native.newTextField( ... ) native.setKeyboardFocus( field )