Copy and paste Android text and android text

Source: Internet
Author: User

Copy and paste Android text and android text

Android provides a simple copy and paste function. The code is simple.

Copy the text code:

ClipboardManager cbm = (ClipboardManager) MainActivity. this. getSystemService (Context. CLIPBOARD_SERVICE); cbm. setText ("Text to be copied ");

Code for pasting text:

ClipboardManager paste = (ClipboardManager) MainActivity.this                 .getSystemService(Context.CLIPBOARD_SERVICE);                 String content=plaster.getText().toString(); 

But after the API11 copy and paste is different, in fact, is the problem of the package, see the http://www.apkbus.com/android-174549-1-1.html

Paste the original text here

In the previous project, there was a copy and paste function. However, there were differences between the copy and paste functions after api11, and there were only a part of them online. Now I will share them with you;
Public void onClick (View v ){
// TODO Auto-generated method stub
Switch (v. getId ()){
Case R. id. top_back:
Finish ();
Break;
Case R. id. btn_invited_copy:
Int sdkInt = Build. VERSION. SDK_INT;
If (sdkInt> Build. VERSION_CODES.HONEYCOMB) {// api11
ClipboardManager copy = (ClipboardManager) ActMyInvitationCode. this
. GetSystemService (Context. CLIPBOARD_SERVICE );
Copy. setText (invitationCode );
Toast. makeText (ActMyInvitationCode. this, "the invitation code is successfully copied to the Clipboard ",
Toast. LENGTH_SHORT). show ();
} Else if (sdkInt <= Build. VERSION_CODES.HONEYCOMB ){
Android. text. ClipboardManager copyq = (android. text. ClipboardManager) ActMyInvitationCode. this
. GetSystemService (Context. CLIPBOARD_SERVICE );
Copyq. setText (invitationCode );
Toast. makeText (ActMyInvitationCode. this, "the invitation code is successfully copied to the Clipboard ",
Toast. LENGTH_SHORT). show ();
}
Break;
}
}
Some children's shoes have not yet seen the difference. android. content. ClipboardManager was used after api 11, while android. text. ClipboardManager was used before api11;

】  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.