edittext.settext() 将键盘类型更改为默认值 [从 ?123 到 ABC]

edittext.settext() changes the keyboard type to default [ from ?123 to ABC](edittext.settext() 将键盘类型更改为默认值 [从 ?123 到 ABC])
本文介绍了edittext.settext() 将键盘类型更改为默认值 [从 ?123 到 ABC]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的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? 切换按钮)并输入一些数字后,键盘变回 ABC.此代码可以在三星设备 s3 和 sywpe 上正常工作,但不能在与 L 和 HTC one 的 nexus 上工作

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

当我注释 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 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

但要使用附加,我必须在不使用 settext 的情况下清除 edittext,此链接 救援

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);

现在像魅力一样工作

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)