读书人

android EditText 输入字符时自动调整

发布时间: 2013-01-11 11:57:35 作者: rapoo

android EditText 输入字符时自动调整插入“-”

例如 在EditText输入框输入 123456789 就自动调整为 1234-4568-8889

谁知道怎么实现一边输入就一边调整 ,拜谢!


[解决办法]
//限制两位小数
txtMoney.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start, int before,
int count) {

}

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

}

public void afterTextChanged(Editable s) {
String temp = s.toString();
int posDot = temp.indexOf(".");
System.out.println(posDot);
if (posDot <0)
return;
if(posDot==0)
{
s.clear();
}
if (temp.length() - posDot - 1 > 2) {
s.delete(posDot + 3, posDot + 4);
}

}
});

这是我限制两位小数输入的方法,你看看有什么启发

读书人网 >Android

热点推荐