2011-09-26 90 views
4

作爲android的新手我有一些代碼組合如下,目的是根據自定義語言環境顯示不同的特定數字12345.66。然而,它只是墜毀我的測試應用程序,我無法弄清楚爲什麼...在這裏感謝一些幫助。提前感謝!android - 基於語言環境的數字格式化

//get current locale and display number 
Configuration sysConfig = getResources().getConfiguration(); 
Locale curLocale = sysConfig.locale; 
String aNumber = "12345.66"; 
NumberFormat nf = NumberFormat.getInstance(curLocale); 
aNumber = nf.format(aNumber); 
numberText.setText(R.string.numberText + aNumber); 

Layout.xml:

<TextView 
    android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
    android:id="@+id/nbumberText" 
/> 
+0

你會得到什麼例外? – SLaks

+0

錯誤消息顯示:抱歉,該應用程序意外停止。請再試一次。然後我必須強制關閉應用程序。 – Liliw

回答

0

這種說法很可疑:

numberText.setText(R.string.numberText + aNumber的);

你是什麼意思?這是一個錯字嗎?

要顯示格式的數字,也許你應該只需要:

numberText.setText(aNumber的);

順便說一句,我想你還沒有使用過調試器。一個嚴肅的開發者肯定需要這個

+0

謝謝,試過「numberText.setText(aNumber);」但仍然無法正常工作。所以基本上我認爲numberformat和parsing存在一些問題,但是我不能分辨出什麼是錯誤的,並且我無法從調試器中得到線索...... – Liliw

相關問題