Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut, copy, paste in android

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

like image 563
Nibha Jain Avatar asked May 31 '11 09:05

Nibha Jain


1 Answers

for copy data

ClipData clip = ClipData.newPlainText("simple text",Value);
ClipMan.setPrimaryClip(clip);

and get data which was copied

CharSequence pasteData="";
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
pasteData = item.getText();

in your case you can use EditText.getText() instead of Value.. and EditText.setText(pasteData); for paste that data.

like image 68
Niranj Patel Avatar answered Oct 06 '22 01:10

Niranj Patel