在android中剪切、复制、粘贴

Cut, copy, paste in android(在android中剪切、复制、粘贴)

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

问题描述

我想在我的 EditText 中实现剪切、复制、粘贴功能,我尝试使用以下代码:

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());

用于粘贴文本,但它会将整个文本粘贴到另一个编辑框中..我想复制选定的文本并将该文本粘贴到同一个编辑框中,就像普通记事本一样..

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..

非常感谢任何建议...谢谢!!

Any suggestions are greatly appreciated... Thanks !!

推荐答案

我终于可以复制粘贴到我的应用程序中了..现在我可以使用此代码仅粘贴选定的文本:

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());

这篇关于在android中剪切、复制、粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在android中剪切、复制、粘贴

基础教程推荐