Reputation: 532
I have a requirement where i have to implement Buttons which can move the cursor up and down the line in a multi line Edittext.
I went through the Developer website and found that Selection class http://developer.android.com/reference/android/text/Selection.html can be used, but i am not able to use it..
Please help me here..
Thank you.
Upvotes: 2
Views: 2901
Reputation: 78
I copied the code and made a little modification below, then appended it to my class.
public boolean moveDown(Layout layout) {
int start = myTextbox.getSelectionStart();
int end = myTextbox.getSelectionEnd();
if (start != end) {
int min = Math.min(start, end);
int max = Math.max(start, end);
myTextbox.setSelection(max);
if (min == 0 && max == myTextbox.length()) {
return false;
}
return true;
} else {
int line = layout.getLineForOffset(end);
if (line < layout.getLineCount() - 1) {
int move;
if (layout.getParagraphDirection(line) ==
layout.getParagraphDirection(line + 1)) {
float h = layout.getPrimaryHorizontal(end);
move = layout.getOffsetForHorizontal(line + 1, h);
} else {
move = layout.getLineStart(line + 1);
}
myTextbox.setSelection(move);
return true;
}
}
return false;
}
I hope this will be useful.
If somebody knows how to use real method without recreating it, please share :D
Upvotes: 1
Reputation: 2958
I am not sure about this code but it may help you to some extend....
just go through the code from the following url. i might help you to find out solution.
Upvotes: 1