2013-04-08 69 views
1

我試圖動態格式上TextView由用戶輸入的值,具體是什麼我試圖做的是:格式貨幣動態上的TextView

1. TextView text = "" 
2. User entered = "4" 
3. TextView text = 0.04 
4. User entered = "5" 
5. TextView text = 0.45 
6. User entered = "6" 
7. TextView text = 4.56 

等等...

我使用TextWatcheronTextChanged方法存根,但我不知道如何實現此邏輯。

實現此功能的最簡單方法是什麼?

回答

3

你必須在這種情況下使用NumberFormat,e.g:

double moneyCurrency = 100.1; 
NumberFormat baseFormat = NumberFormat.getCurrencyInstance(); 
String moneyString = baseFormat.format(moneyCurrency);