Implementation of the clipart for Android

Source: Internet
Author: User

1. inherit edittext

2. Rewrite the ontouchevent method.

Public Boolean ontouchevent (motionevent event) {editable ED = This. geteditabletext (); // get action int action = event. getaction (); // layout used to display text layout = This. getlayout ();

// Obtain the row number

Int pointy = layout. getlineforvertical (getscrolly () + (INT) event. gety (); Switch (Action) {Case motionevent. action_down:/* indicates the memory start point when the finger is pressed. The first is the number of rows, and the second is the start point */startpoint = layout. getoffsetforhorizontal (pointy, event. getx ());

// The first parameter editable is a subclass, and the second parameter is the start point.

Selection. setselection (ED, startpoint); break; Case motionevent. action_move:/* memory dead point when fingers move */Endpoint = layout. getoffsetforhorizontal (pointy, event. getx (); selection. setselection (ED, startpoint, endpoint); break;} return true ;}

 

3. truncate the string based on the above startpoint and Endpoint

Public String getselectedtext () {return this. gettext (). tostring (). substring (startpoint, endpoint );}

 

4. Obtain clipboardmanager

Clipboardmanage cmanager = (clipboardmanager) getsystemservice (clipboard_service );

 

5. Copy the intercepted string eV to an instance of editetext.

Cmanager. settext (EV. getselectedtext ());

 

6. Obtain the copied string

Settext (cmanager. gettext ());

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.