setText fails to show a number as text in a TextView

五迷三道 提交于 2019-11-26 13:53:36
codeMagic

The problem is with lines like this

addAmount.setText(aAmt);

where aAmt is an int. This looks for a resource with the id of whatever aAmt is. You need to cast it to a String first like

addAmount.setText(String.valueOf(aAmt));

There are overloaded setText() methods. See the docs

This post goes into some more detail as to how this actually works

Rakesh Dey

You can Try one of these two:

  1. addAmount.setText("" + aAmt);
  2. addAmount.setText(String.valueOf(aAmt));

you'll get a String result without any error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!