亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

EditText限制輸入數(shù)字,精確到小數(shù)點(diǎn)后1位的設(shè)置方法

 更新時(shí)間:2017年04月15日 09:34:28   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇EditText限制輸入數(shù)字,精確到小數(shù)點(diǎn)后1位的設(shè)置方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

在EditText的布局文件里面設(shè)置:

android:inputType="numberDecimal"

在代碼中:

/** 輸入框小數(shù)的位數(shù)*/
private static final int DECIMAL_DIGITS = 1;

InputFilter lengthfilter = new InputFilter() {
  public CharSequence filter(CharSequence source, int start, int end,
                Spanned dest, int dstart, int dend) {
    // 刪除等特殊字符,直接返回
    if ("".equals(source.toString())) {
      return null;
    }
    String dValue = dest.toString();
    String[] splitArray = dValue.split("http://.");
    if (splitArray.length > 1) {
      String dotValue = splitArray[1];
      int diff = dotValue.length() + 1 - DECIMAL_DIGITS;
      if (diff > 0) {
        return source.subSequence(start, end - diff);
      }
    }
    return null;
  }
};
et_content.setFilters(new InputFilter[] { lengthfilter });

以上這篇EditText限制輸入數(shù)字,精確到小數(shù)點(diǎn)后1位的設(shè)置方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論