剪切,复制,粘贴在机器人 [英] Cut, copy, paste in android

查看:315
本文介绍了剪切,复制,粘贴在机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现我的EditText剪切,复制,粘贴功能,我试着用下面的code:

I want to implement the cut,copy, paste functionality in my EditText,i tried with the following code :

    ClipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    editbox1.setText(ClipMan.getText());

有关粘贴文本,但它粘贴到另一个Editbox..I整个文本要复制选定的文本,粘贴在同一个编辑框的文本就像普通记事本作品。

for paste the text,but it paste the whole text in another Editbox..I want to copy the selected text and paste that text in the same Editbox just like the normal notepad works..

任何建议都大大pciated AP $ P $ ... 谢谢!

Any suggestions are greatly appreciated... Thanks !!

推荐答案

最后我能够复制,粘贴在我的application..now我可以只粘贴选定的文本使用此code:

Finally i am able to copy ,paste in my application..now i can paste only selected text by using this code :

Editable s1;
EditText editbox2;

要复制选定的文本:

       if(editbox2.getSelectionEnd() > editbox2.getSelectionStart()) 
        {
            s1 = (Editable) editbox2.getText().subSequence(editbox2.getSelectionStart(), editbox2.getSelectionEnd());
        }else
        {
            s1 = (Editable) editbox2.getText().subSequence(editbox2.getSelectionEnd(), editbox2.getSelectionStart());
        }

要粘贴选定的文本:

             editbox2.getText().replace(Math.min(editbox2.getSelectionStart(),editbox2.getSelectionEnd()), Math.max(editbox2.getSelectionStart(), editbox2.getSelectionEnd()),s1, 0, s1.length());

这篇关于剪切,复制,粘贴在机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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