Android:在当前位置将文本插入EditText [英] Android: Insert text into EditText at current position

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

问题描述

我想通过按下按钮将常量字符串插入到 EditText 中.该字符串应插入到 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.

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

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