How to use getCurrencyInstance and format in low api?

浪子不回头ぞ 提交于 2019-12-12 18:23:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/40390313/how-to-use-getcurrencyinstance-and-format-in-low-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!