Pra*_*een 3 android android-edittext
有没有办法限制EditText在运行时只能输入2位数字.
例如:
如果我设置我的android:inputType="numberDecimal",我输入其中的值.它接受值123.000000000000.但我想限制它像123.00
有没有可能的方法呢?
看一下以下帖子,也许对你有所帮助:
EditText txtInput = (EditText) findViewById(R.id.txtInput);
txtInput.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable edt)
{
String temp = edt.toString();
int posDot = temp.indexOf(".");
if (posDot <= 0) return;
if (temp.length() - posDot - 1 > 2)
{
edt.delete(posDot + 3, posDot + 4);
}
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1048 次 |
| 最近记录: |