android:限制EditText输入位数
2016-03-12 15:41
381 查看
withDrawcet.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence s, int i, int i1, int i2) { if (s.toString().contains(".")) { if (s.length() - 1 - s.toString().indexOf(".") > 2) { s = s.toString().subSequence(0, s.toString().indexOf(".") + 3); withDrawcet.setText(s); withDrawcet.setSelection(s.length()); } } if (s.toString().trim().substring(0).equals(".")) { s = "0" + s; withDrawcet.setText(s); withDrawcet.setSelection(2); } if (s.toString().startsWith("0") && s.toString().trim().length() > 1) { if (!s.toString().substring(1, 2).equals(".")) { withDrawcet.setText(s.subSequence(0, 1)); withDrawcet.setSelection(1); return; } } } @Override public void afterTextChanged(Editable editable) {}};
相关文章推荐
- android自定义控件(二),简易的数值输入器
- android之layout_gravity 和 gravity 两者之间的区别
- Android SlidingMenu使用详解
- Android Studio 运行 遇到:Failed to read key from keystore
- android用服务service与广播broadcastreceiver创建开机启动服务
- 下载android源码
- Android View 绘制流程 与invalidate 和postInvalidate 分析--从源码角度
- android学习笔记——访问本机服务器的文件内容
- android学习笔记——Service服务初探
- android学习笔记——AsyncTask异步消息处理机制简单介绍及使用
- android学习笔记——android多线程编程初探
- android学习笔记——收发短信练习
- android学习笔记——内容提供器
- Intent和IntentFilter的笔记(develper.android.com)
- Android点击事件的四种写法
- 设置EditText中的所有字体颜色
- Android四大组件之 Activity
- Android数据库升级总结
- 使用GridViewWithHeaderAndFooter为gridView添加页头的方法
- Kotlin Android入门学习一