TextView always showing value as “0” on UI

三世轮回 提交于 2020-01-17 02:26:08

问题


I am using a simple TextView and updating its value in onPostExecute of a AsyncTask. But every time its showing "0" on UI.

My code is:

TextView tv = (TextView)findViewById(R.id.tv);
tv.setText(calculation());


private int calculation(){
return output;
}

What is going wrong here, no error comming in stack trace? please help me?


回答1:


Your code tv.setText(calculation()); tryind to take string from Resourses cause you set value as int.

Use tv.setText(String.valueOf(calculation()));




回答2:


try this

tv.setText(calculation()+"");

As TextView only accept string in settext, Adding +"" to int will make it as string. and make sure that your method is returning the right value.



来源:https://stackoverflow.com/questions/27226834/textview-always-showing-value-as-0-on-ui

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