问题
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