3

TextField是否可以在 J2ME中设置插入符号位置?有一个方法getCaretPosition(),但我需要设置它。

4

1 回答 1

2

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 string s at the current caret position...

于 2012-04-23T07:25:01.580 回答