如何设置文本末尾的插入符号位置?
I want to set the caret position to the end of a Text after appending text to a StyledText.
How do I achieve this? Set caret at the end of the text
This is in continuation to my earlier question
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未使用过 StyledText,但查看 API 显示了一个名为
setCaretOffset( int offset )
的方法,该方法采用一个数字,该数字是正文的开头。因此,您可以调用 getText(),找到其长度,然后将插入符号设置为该数字作为偏移量。*我喜欢特拉维斯下面发布的答案。我没有注意到 StyledSheet 上的 getCharacterCount() 方法。这可能比获取文本和长度要便宜一些。
I have never used StyledText but looking at the API shows a method called
setCaretOffset( int offset )
which takes a number that is the offset from the beginning of the text. So you could callgetText()
, find its length, and then set the caret to be that number as the offset.*I like the answer that Travis posted below. I didn't notice the method getCharacterCount() on StyledSheet. That is probably a little cheaper then getting the text then the length.
我找到了我的问题的解决方案。
我尝试过这个,但这对我来说并不可取。
这对我有用!
我感谢大家的上述回答。
I found a solution to my question.
I tried this, but this was not preferable to me.
This worked for me!
My gratitude to all for the above answers.