用户输入的实时编辑 [英] Live editing of users input
问题描述
是否有可能自动插入字符到的EditText
作为用户输入数据
Is it possible to auto insert characters into an EditText
as the user inputs data?
即。如果用户输入一个长的数字,如 123456789012
,是有可能出现这个数字,因为他是键入它在编辑文本框中,但有一个破折号每4个人物?
I.e. if the user is entering a long number such as 123456789012
, is it possible for this number to appear as he is typing it in the edit text box, but with a dash every 4th character?
所以,当你键入数字,你会上面看到它被输入到的EditText
框,但应该是这样的:1234-5678-9012
So as you type the number above you would see it being entered in the EditText
box but would look like this: 1234-5678-9012.
目前我有一个应用程序,你可以输入一个长的数字,然后preSS一个按钮,并将其插入破折号你,但我很好奇,如果它可以在您键入做?
Currently I have an app where you can enter a long number and then press a button and it inserts the dashes for you, but I'm curious if it could be done as you type?
非常感谢您的帮助。
推荐答案
通过标记机器人,我认为你正在讨论关于Android EDITTEXT,是让你可以通过监听TextChangedListener做到这一点,
By tagging android, I think you are discussing about android editText, is so you can do it by listening the TextChangedListener,
编辑:退格键
editText.addTextChangedListener(new TextWatcher() {
int len=0;
@Override
public void afterTextChanged(Editable s) {
String str = editText.getText().toString();
if(str.length()==4&& len <str.length()){//len check for backspace
editText.append("-");
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
String str = editText.getText().toString();
len = str.length();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
这篇关于用户输入的实时编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!