2011-09-26 85 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

相关问题