问题描述
我试图在编辑文本中成对显示十六进制输入。我正在使用文本观察器来拦截可编辑值并添加空格以将它们分组。这是最接近的解决方案。
public void afterTextChanged(Editable s) {
String text = addspaces(s.toString());
int cursorPos = editText.getSelectionStart();
String sInput = s.toString();
...
try {
sInput = sInput.substring(sInput.length()-3);
int cur = StringUtils.countMatches(sInput," ");
cursorPos = cursorPos + cur;
editText.setText(text);
editText.setSelection(Math.min(cursorPos,text.length()));
}catch (Exception e ) {
editText.setSelection(text.length());
}
}
@tests
- 输入 1122334455667788(空编辑文本)=> 输出 11 22 33 44 55 66 77 88
- 输入 1234567890123456(空编辑文本)=> 输出 12 43 65 87 09 21 43 65
目标是在第二种情况下输出为“12 34 56 78 90 12 34 56”。
(也有可能edit-text已经有了值,用户应该可以在任意位置插入,这意味着我不能将光标位置设置为带空格的文本长度)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)