格式化ValueAmimator setText与十进制格式Android JAVA



我有一个动画setText显示。我从JSON响应中获取字符串值,并用valueAnimator显示它。

我需要将最终的setText格式化为1000s格式(#,####(

例如

目前我得到:50125

预期:50125

DecimalFormat decim = new DecimalFormat("#,###");
//Total no animate
ValueAnimator animator = new ValueAnimator();
animator.setObjectValues(0, Integer.parseInt(total_no));
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
tvtotal_no.setText(String.valueOf(animation.getAnimatedValue()));
//tvtotal_no.setText(decim.format(Integer.parseInt(total_cases)));
}
});
animator.setDuration(500);
animator.start();

您需要实际使用DecimalFormat:

DecimalFormat decim = new DecimalFormat("#,###");
//Total no animate
ValueAnimator animator = new ValueAnimator();
animator.setObjectValues(0, Integer.parseInt(total_no));
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
tvtotal_no.setText(decim.format(animation.getAnimatedValue()));
}
});
animator.setDuration(500);
animator.start();

最新更新