Android Clipboard: Copy&Paste

I know it’s pretty straightforward but I haven’t found any example out there of using the clipboard from Android Applications. So for beginners like me, here is an example of how to copy and paste some text using ClipboardManager object.

This is the Copy button code:

// Copy EditCopy text to the ClipBoard
private void copyToClipBoard()
{
ClipboardManager ClipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipMan.setText(editCopy.getText());
}

and the Paste button source:

// Paste ClipBoard Text to EditPaste
private void pasteFromClipBoard()
{
ClipboardManager ClipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
editPaste.setText(ClipMan.getText());
}

Simple, right? 😉 By the way, editPaste and editCopy are both EditText class objects. In case you need it, the whole project can be downloaded from my GitHub repository.

_______________________________________________________________

Advertisements

5 Responses to “Android Clipboard: Copy&Paste”


  1. 1 shamtest May 14, 2011 at 9:44 am

    I can’t seem to look at this post from my iphone!

  2. 2 Shubham June 4, 2011 at 6:02 am

    Hello,

    thanks for sharing your knowledge.
    Do u have any idea how can we use this Clipboard functionality for Images.

    Thanks

  3. 3 Shubham June 10, 2011 at 12:47 pm

    pls reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Who’s in charge here?

Follow me on Quoders Blog…



Quoders Twitter

License


%d bloggers like this: