Issue
I´ve got the problem, that Android Studio reminds me to use the string.xml for set the text. The following gives me the hint: Do not concatenate text displayed with setText. Use resource string with placeholders.
public int points = 0;
public TextView tv_points;
tv_points.setText("Points: " + points);
Okay if i use the string xml with this code it does not what i want:
<string name="points_string">Points: </string>
public int points = 0;
public TextView tv_points;
tv_points.setText((R.string.points_string) + points);
It brings no error and no hint, but is wrong. I do not get the wanted effect to set the points.
Solution
You need to format the string using strings.xml like this:
<string name="points_string">Points: %1$d</string>
Then you can use it like this:
tv_points.setText(getResources().getString(R.string.points_string, points));
Answered By - Pulak
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.