格式化信用卡输入像(XXXX XXXX XXXX XXXX)在android系统 [英] Formatting credit card input like (xxxx xxxx xxxx xxxx) in android
问题描述
如何在Android的设置信用卡号码上面格式(之间的空格)?谁能帮我这个?
How to set credit card number in above format(spaces in between) in android? Can anyone help me with this?
推荐答案
如果我没看错,你想去做,因为用户每四个字符输入后的EditText提供输入一个空格应该放在后。
If i am not wrong, you want to do like, as user provides input in edittext after every four characters typed, a space should be placed after it.
如果这是你需要的东西,那么你就可以实现:
If this is the thing you need, then you can implement:
editText.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
// apply your logic for putting space after every four characters typed
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
});
编辑:
我认为你可以使用 PatternMatcher
类。按照第[developer.android.com]以下链接:
I think you can use PatternMatcher
class. Follow these links on [developer.android.com]:
http://developer.android.com/reference/android/os/ PatternMatcher.html
http://developer.android.com/reference/java/ UTIL /正则表达式/ Pattern.html
http://developer.android.com/reference/java/ UTIL /正则表达式/ Matcher.html
检查教程在这里: http://www.vogella.com /articles/JavaRegularEx$p$pssions/article.html
这篇关于格式化信用卡输入像(XXXX XXXX XXXX XXXX)在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!