为android创建自定义输入类型

我的要求是,用户应该只能输入数字0到9,并且在每4个字符后,“ - ”符号会自动附加到edittext.user不应该删除edittext的任何部分除了最后。请建议锄头这样做。 用户不应该将光标移动到键入文本中间的任何位置,并且能够将其删除。怎么做到这一点?当用户移动光标位置时调用什么事件?     
已邀请:
您的第一个要求是0-9仅通过在XML用户类型编号中设置编辑文本属性来实现 并在编辑文本设置文本观察者监听器中计算文本,编辑文本对象和计数单词,然后您可以附加“ - ”字符。     
我找到了解决问题的方法:用户不应该将光标移动到键入文本中间的任何位置。我们需要扩展
EditText
并添加覆盖以下函数:
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
    // TODO Auto-generated method stub
    // this method will check if the cursor is moved. if yes then bring back
    // the cursor to the end so that the user cannot delete anythign from
    // the middle of the text(here sub id). Any editing will only be
    // possible at the end of the text
    if (selStart == selEnd) {
        int length = getText().toString().length();
        setSelection(length);
    }
    super.onSelectionChanged(selStart, selEnd);
}
    

要回复问题请先登录注册