edittext.settext()更改键盘类型为默认[而来?123 ABC] [英] edittext.settext() changes the keyboard type to default [ from ?123 to ABC]

查看:279
本文介绍了edittext.settext()更改键盘类型为默认[而来?123 ABC]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下code为我的EditText格式,因为它可以采取任何输入我没有设置任何输入类型:

I have following code for my edittext formatting, since it can take any input I am not setting any input type:

if (cardNumberEditText != null) {
    cardNumberEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            int currSel = cardNumberEditText.getSelectionStart();
            cardNumberEditText.removeTextChangedListener(textWatcher);
            .
            .
            cardNumberEditText.setText(formattedNumber);
            .
            .
            cardNumberEditText.setSelection(currSel);
            cardNumberEditText.addTextChangedListener(textWatcher);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
}

所以最初我得到默认的输入类型是ABC,现在当我将其更改为?123(使用ABC / 123?toggel按钮),并输入一些数字键盘变回ABC之后。这code接缝做工精细的三星设备S3和sywpe但不与L和的HTC One关系

So initially I get the default input type which is ABC, now when I change it to ?123 (using ABC/123? toggel button) and after entering some number the keyboard changes back to ABC. This code seams to work fine on samsung devices s3 and sywpe but not on nexus with L and HTC one

当我评论的所有code里面onTextChanged,它工作正常。所以,当我调查,我发现,罪魁祸首是cardNumberEditText.setText(formattedNumber);

When I comment all the code inside onTextChanged, it works fine. So when I investigated I found out that culprit is cardNumberEditText.setText(formattedNumber);

我不设置任何输入类型,我只是使用键盘上的ABC /?123切换键用于切换

I am not setting any input type, I am just using the ABC/?123 toggle key on keyboard for switching

任何帮助/建议,为什么发生这种情况(在少数设备),我该如何改正?

Any help/suggestion why this is happening (on few devices) and how can I correct it ??

推荐答案

finnaly懂了工作,不得不在评论中提到的多种解决方案结合了上述

finnaly got it working, had to combine multiple solutions mentioned in the comments above

由于犯了的setText,我发现了一个替代它 - 追加

since the guilty was settext, I found a replacement for it - append

而是利用追加我不得不清除的EditText不使用的setText,此链接救援

but to use append I had to clear edittext without using settext, this link to the rescue

如此替换

cardNumberEditText.setText(formattedNumber);

cardNumberEditText.getText().clear();
cardNumberEditText.append(formattedNumber);

就像一个魅力现在

works like a charm now

这篇关于edittext.settext()更改键盘类型为默认[而来?123 ABC]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆