Text box questions

I’m building text box to fit all the screen and I have few questions:

  1. how do I get phase “submitted” or “ended” on android device to hide the keyboard. On ios there is a hide keyboard button, but there is none on android. what should I do to remove the keyboard, maybe I can do it through some touch listener that removes keyboard, f.e. when the user touches the screen?

  2. How do I now how many text is printed or where is the cursor? I need to know this in order to move the box upwards when the text is going to be covered by the keyboard. How to do it?

thanks!

For #1, actually there is only a hide keyboard button on the iPad keyboard.  There isn’t one on the iPhone keyboard that I’m aware of.  Many Android devices present a keyboard hide button in their soft button bar when the keyboard is shown.   But to answer you question, see:

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

passing the value nil to this function dismisses the keyboard.

Rob

I’m not sure how to get the cursor information, but you can get the current text value using the objects .text attribute.  Then you can calculate about how many lines and knowing the font size you can estimate it’s height.

Rob

Oh, I’ve tested it only on iPad.

I’m aware of setKeyboardFocus but I wondered how to better use it. I think I’ll just create a button “done”.
 

thanks for your advice. I’ll try calculating line number to do this.

But how can I access the number of lines in the text? to know the number of symbols I use string.len, but it’s not good because user can have many lines, but not many symbols.

That becomes tricker to figure out.  I thought you just need to know how many lines there were.

I create a text object which texts the input text. text.height works with it. so I know the height of the text(that’s exactly what I needed) but how to make the textbox adjust its position according to that size? any suggestions?

For #1, actually there is only a hide keyboard button on the iPad keyboard.  There isn’t one on the iPhone keyboard that I’m aware of.  Many Android devices present a keyboard hide button in their soft button bar when the keyboard is shown.   But to answer you question, see:

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

passing the value nil to this function dismisses the keyboard.

Rob

I’m not sure how to get the cursor information, but you can get the current text value using the objects .text attribute.  Then you can calculate about how many lines and knowing the font size you can estimate it’s height.

Rob

Oh, I’ve tested it only on iPad.

I’m aware of setKeyboardFocus but I wondered how to better use it. I think I’ll just create a button “done”.
 

thanks for your advice. I’ll try calculating line number to do this.

But how can I access the number of lines in the text? to know the number of symbols I use string.len, but it’s not good because user can have many lines, but not many symbols.

That becomes tricker to figure out.  I thought you just need to know how many lines there were.

I create a text object which texts the input text. text.height works with it. so I know the height of the text(that’s exactly what I needed) but how to make the textbox adjust its position according to that size? any suggestions?