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