我正在使用ListView
包含ProgressBar
和的自定义TextView
。现在,进度数据可能包含float
值,因此我想在TextView中显示浮点值。但是它显示错误:无法将'43 .20'解析为int。如果我通过int,那么它工作正常。
如何预防这个问题?
我的示例代码:
final SimpleAdapter adapter = new SimpleAdapter(this, aaReportData, R.layout.report_card1, new String[] { "Topic", "Accuracy", "Accuracy" },
new int[] { R.id.tvTopic, R.id.pbTopicAccuracy, R.id.tvAccuracy });
tvAccuracy
是我正在谈论的TextView。
日志:
03-11 12:32:38.913: E/AndroidRuntime(1187): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mytestbuddy.anatomy/com.mytestbuddy.anatomy.ReportCard}: java.lang.NumberFormatException: unable to parse '43.24' as integer
首先要像这样将浮点值转换为字符串
String Str = String.valueOf("43.50");
然后将str分配给textview。
TextView txt = new TextView(this);
txt.settext(Str);
像这样,试试这个。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句