TextField
是否可以在 J2ME中设置插入符号位置?有一个方法getCaretPosition()
,但我需要设置它。
1 回答
In MIDP 2, TextField API does not provide a way for application developer to set caret position.
The most likely reason is that API designers decided that exposing such an API could led to negative user experience: imagine application suddenly moving caret from under your fingers right when you're typing a text - that's how setCaretPosition
would work. If you plan something like that in your application, think twice about how it would look for its users (I for one would probably broke my phone and curse a MIDlet that would behave like that).
- side note - purpose of "auxiliary" method
getCaretPosition
you mentioned is to support insert API:...If the application needs to simulate typing of characters it can determine the location of the current insertion point ("caret") using the with getCaretPosition() method. For example,
text.insert(s, text.getCaretPosition())
inserts the strings
at the current caret position...