安卓:插入文字的EditText在当前位置 [英] Android: Insert text into EditText at current position

查看:389
本文介绍了安卓:插入文字的EditText在当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要插入一个常量字符串变成一个EditText通过一个按钮preSS。字符串应插入在的EditText的当前位置。 如果我使用 EditText.append 文本被插入到的EditText的末尾。

I want to insert a constant string into an EditText by the press of a button. The string should be inserted at the current position in the EditText. If I use EditText.append the text gets inserted at the end of the EditText.

我怎么能这样做?我无法找到一个合适的方法。

How can I do that? I couldn't find a suitable method.

推荐答案

尝试使用 EditText.getSelectionStart()获取光标的当前位置。然后你可以使用String.subString前后光标之后获得的文本,在中间插入文本。

Try using EditText.getSelectionStart() to get the current position of the cursor. Then you can use String.subString to get the text before and after the cursor and insert your text in the middle.

没有尝试过,但。

这篇关于安卓:插入文字的EditText在当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆