- Selection is a tool class. It is a tool class for range selection. its own methods are static. I tested all the methods and stayed up late again. the test is performed in an ontouchevent method that inherits the edittext subclass. this is a summary.
- The real parameter of text is geteditabletext (), and the real parameter of layout is getlayout ()
- Method of the selected area:
- Selection. extenddown (spannable text, layout); // coordinates of the current cursor, selected to the (X axis) Position of the next row
1 2 3 4 cursor 5 6 7 8 9
1 2 3 4 5 6 7 8 9
- Selection. extendup (spannable text, layout); // coordinates of the current cursor, selected to the (X axis) Position of the previous line
1 2 3 4 5 6 7 8 9
1 2 3 4 cursor 5 6 7 8 9
- Selection. extendleft (spannable text, layout); // coordinates of the current cursor, selected to the position of the X-1
1 2 3 4 5 6 7 8 9
1 2 3 4 cursor 5 6 7 8 9
- Selection. extendright (spannable text, layout); // coordinates of the current cursor, selected to the position x + 1
1 2 3 4 5 6 7 8 9
1 2 3 4 cursor 5 6 7 8 9
- Selection. extendtoleftedge (spannable text, layout); // coordinates of the current cursor, selected to the leftmost position of the same row
1 2 3 4 5 6 7 8 9
1 2 3 4 cursor 5 6 7 8 9
- Selection. extendtorightedge (spannable text, layout); // coordinates of the current cursor, which is selected to the rightmost position of the same row
1 2 3 4 5 6 7 8 9
1 2 3 4 cursor 5 6 7 8 9
- Jump cursor method:
- Selection. movedown (spannable text, layout); // The coordinates of the current cursor to jump to the position of the next line (X axis)
1 2 3 4 Original cursor 5 6 7 8 9
1 2 3 4 new optical mark 5 6 7 8 9
- There are also moveup, moveleft, and movetoleftedge, which should be explained in conjunction with other methods above! This is omitted.
- Select and cancel all methods at the specified position:
- Selection. setselection (spannable text, int index); // coordinates of the current cursor to jump to the index (index starts from 0), note that it is not moveselection.
For example, selection. setselection (geteditabletext (), 5 );
1 2 3 4 Original cursor 5 New Light mark 6 7 8 9
1 2 3 4 5 6 7 8 9
- Selection. extendselection (spannable text, int index); // coordinates of the current cursor, selected to the position where the index is index (index starts from 0)
For example, selection. extendselection (geteditabletext (), 5 );
1 2 3 4 Original cursor 5 6 7 8 9
1 2 3 4 5 6 7 8 9
- Selection. setselection (spannable text, int start, int stop) // select the area from index start to index stop
For example, selection. setselection (geteditabletext (), 5, 9 );
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
- Selection. selectall (spannable text); // select all
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
- Selection. removeselection (spannable text); // deselect the selected state and reset the cursor coordinates to the beginning.
1 2 3 4 5 6 7 8 9 ==> cursor 1 2 3 4 5 6 7 8 9
1 2 3 4 cursor 5 6 7 8 9 1 2 3 4 5 6 7 8 9
- Int selection. getselectionend (charsequence text)// The Real Text parameter is geteditabletext ()
- If no selected area exists and a cursor exists, the index of the cursor is returned;
- If a selected region exists, the end index of the returned region is returned;
- If no area or cursor is selected,-1 is returned.
- Int selection. getselectionstart (charsequence text)// The Real Text parameter is geteditabletext ()
- If no selected area or cursor exists, the index of the cursor is returned;
- If a selected region exists, the start index of the returned region is returned;
- If no area or cursor is selected,-1 is returned.
The two methods also have edittext. How can I obtain the selected text? The two methods depend on edittext. Take a start index start and end index to determine whether they are the same. If they are different, the text is selected,Selected text = medittext. gettext (). Subsequence (START, end ); |