问题描述
我的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]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!