I want to remove the dollar sign to my amount formatter but its not working I already assigned the replace it it contains an dollar sign. How can I do this?
Here is my code for Text Watcher.
NumberFormat canadaEnglish = NumberFormat.getCurrencyInstance(Locale.CANADA);
public class MoneyTextWatcher implements TextWatcher {
private final WeakReference<EditText> editTextWeakReference;
boolean hasFractionalPart = false;
private EditText editText;
public MoneyTextWatcher(EditText editText) {
editTextWeakReference = new WeakReference<EditText>(editText);
this.editText = editText;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (s.toString().contains(String.valueOf(df.getDecimalFormatSymbols().getDecimalSeparator()))) {
hasFractionalPart = true;
} else {
hasFractionalPart = false;
}
if (mIsInWatcher)
return;
mIsInWatcher = true;
}
@Override
public void afterTextChanged(Editable editable) {
if (editText == null)
return;
String s = editable.toString();
editText.removeTextChangedListener(this);
String cleanString = s.toString().replaceAll("[$,.]", "");
String formatted = "";
System.out.println(cleanString);
BigDecimal parsed = new BigDecimal(cleanString).setScale(2,BigDecimal.ROUND_FLOOR).divide(new BigDecimal(100),BigDecimal.ROUND_FLOOR);
formatted = canadaEnglish.format(parsed).replace("\\$",pesoCurrency);
System.out.println("formatted > " + formatted);
String trimFormatted = formatted.replace("\\$", pesoCurrency);
System.out.println("trimFormatted > " + trimFormatted);
editText.setText(formatted.replace("\\$", ""));
editText.setSelection(formatted.length());
editText.addTextChangedListener(this);
}
}