As an exercise, I make a simple application for pizza ordering - the choice of size (affects the price) plus additional topping (also affects the price).
As a result, the order amount is calculated:
total.setText(getString(R.string.total_price_output) + String.format("%.02f", calculateTotal())); Here total_price_output is the phrase "Total Price: $" in strings.xml, a method calculateTotal () just calculates the total order value, taking into account the size and toppings.
Everything works, but Android Studio highlights this line with a yellow dash, i.e. The code does not comply with the rules of good tone and gives me this recommendation:
Do not concatenate text displayed with setText. Use resource string with placeholders.
How to proceed? Add a variable, assign it everything that now goes to setText () and then call setText () with this variable?
Formatting strings. - post_zeew