您的位置:首页 > 移动开发 > Android开发

EditText 保留两位小数

2015-11-17 14:59 471 查看
源地址:http://blog.sina.com.cn/s/blog_5d66fcf00102vwzv.html

布局XML文件:

android:inputType="numberDecimal"

 

 

源代码:

editMoney = (EditText) findViewById(R.id.EditMoney);

  editMoney.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) {}

  });
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android