Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use getCurrencyInstance and format in low api?

I am getting an error in the following code:

private void displayPrice (int number) {

    TextView price = (TextView)findViewById(R.id.txt_price);
    price.setText(NumberFormat.getCurrencyInstance().format(number));
}

The error I am getting is as follows:

Call requires API level 24 (current min is 14): android.icu.text.NumberFormat#getCurrencyInstance

Android API 24 can use this. How can I use this in low API like API 15?

like image 676
Mohsen Armoun Avatar asked Nov 20 '25 08:11

Mohsen Armoun


1 Answers

Change your import to use java.text.NumberFormat (available from API 1) instead of android.icu.text.NumberFormat (available from API 24).

The ICU4J framework provides better internationalization support, but it is not required.

like image 97
ianhanniballake Avatar answered Nov 22 '25 23:11

ianhanniballake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!