currency_edittext
currency_edittext copied to clipboard
Simple currency formatter for Android EditText
Usage
These lines formats simply your input for default locale.
<faranjit.currency.edittext.CurrencyEditText
android:id="@+id/edt_currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:textColor="@android:color/black" />
You can choose any locale.
<faranjit.currency.edittext.CurrencyEditText
android:id="@+id/edt_currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:textColor="@android:color/black"
app:locale="en_US" />
or
final CurrencyEditText currencyEditText = (CurrencyEditText) findViewById(R.id.edt_currency);
currencyEditText.setLocale(new Locale("en", "US"));
CurrencyEditText
shows currency symbol depending on locale or you can set it not to show.
<faranjit.currency.edittext.CurrencyEditText
android:id="@+id/edt_currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:textColor="@android:color/black"
app:locale="en_US"
app:showSymbol="false" />
or
currencyEditText.showSymbol(false);
If you want to change grouping and monetary seperators for money symbolization you can like this.
<faranjit.currency.edittext.CurrencyEditText
android:id="@+id/edt_currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:textColor="@android:color/black"
app:groupDivider="."
app:monetaryDivider=","
app:locale="en_US"
app:showSymbol="true" />
or
currencyEditText.setGroupDivider('.');
currencyEditText.setMonetaryDivider(',');
When set text to 123450, this gives to output $1.234,50 instead of $1,234.50.
When you want to get double or String value of input it is enough to type these lines:
double d = currencyEditText.getCurrencyDouble();
String s = currencyEditText.getCurrencyText();