Guest User

Untitled

a guest
Nov 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. editTextJumlahTrx = (EditText)findViewById(R.id.editTextJumlahTrx);
  2. editTextJumlahTrx.addTextChangedListener(new TextWatcher(){
  3. private String current = "";
  4. @Override
  5. public void afterTextChanged(Editable s) {
  6.  
  7. }
  8. @Override
  9. public void beforeTextChanged(CharSequence s, int start,
  10. int count, int after) {
  11. }
  12.  
  13. @Override
  14. public void onTextChanged(CharSequence s, int start, int before, int count) {
  15. if (!s.toString().equals(current)) {
  16. editTextJumlahTrx.removeTextChangedListener(this);
  17. Locale localeID = new Locale("in", "ID");
  18. String replaceable = String.format("[%s,.\s]", NumberFormat.getCurrencyInstance(localeID).getCurrency().getSymbol());
  19. String cleanString = s.toString().replaceAll(replaceable, "");
  20.  
  21. double parsed;
  22. parsed = Double.parseDouble(cleanString);
  23.  
  24. NumberFormat formatter = NumberFormat.getCurrencyInstance(localeID);
  25. formatter.setMaximumFractionDigits(0);
  26. String formatted = formatter.format((parsed));
  27.  
  28. current = formatted;
  29. editTextJumlahTrx.setText(formatted);
  30. editTextJumlahTrx.setSelection(formatted.length());
  31. editTextJumlahTrx.addTextChangedListener(this);
  32. }
  33. }
  34. });
  35.  
  36. at id.sulistiyanto.pendaftaranpraktikum.MainActivity$2.onTextChanged(MainActivity.java:111)
  37.  
  38. parsed = Double.parseDouble(cleanString);
Add Comment
Please, Sign In to add comment