我的自定义Edittext
已从AppCompatEditText
延长,并显示日期文字,如"10.02.2012 10:40"
当用户点击一次时,文字的任何部分,应自动选择零件。
例如:
为此,在我的自定义edittext中,我覆盖了onSelectonChange
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
if (isFocused() && isCursorVisible() && isPressed()) {
int[] aFoo = findPartOfText(selStart, selEnd);
selStart = aFoo [0];
selEnd = aFoo [1];
}
super.onSelectionChanged(selStart, selEnd);
}
它不会改变任何东西。我也试过这个:
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
//Select first 3 characters
super.onSelectionChanged(0, 2);
}
结果相同。它也不会选择前3个字符。
答案 0 :(得分:0)
尝试EditText.setSelection(int start,int end)。当调用onSelectionChanged时,检查光标位置或选择,并调用setSelection进行更改。