删除android中textWatcher中的美元符号和逗号

时间:2012-09-06 10:13:28

标签: android android-emulator click android-edittext textwatcher

在edittext中输入整数时,我单独用逗号标记并使其正常工作,现在我想从它们只获得整数并存储在变量中进行一些计算,如何做到这一点?提前谢谢..

这是我的代码..

私有TextWatcher textWatcher = new TextWatcher(){

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

     }
     boolean isEdiging;

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

     @Override public void afterTextChanged(Editable s) {
         if(isEdiging) return;
         isEdiging = true;



         String str = s.toString().replaceAll( "[^\\d]", "" );
         double s1 = Double.parseDouble(str);

         NumberFormat nf2 = NumberFormat.getInstance(Locale.ENGLISH);
         ((DecimalFormat)nf2).applyPattern("$ ###,###.###");
         s.replace(0, s.length(), nf2.format(s1));
         isEdiging = false;
     }
};    

0 个答案:

没有答案