andreluizreis
8/18/2017 - 4:25 PM

Add variables String.xml. Font: https://code.tutsplus.com/tutorials/android-sdk-quick-tip-formatting-resource-strings--mobile-1775

<string name="diseaseMessage">%1$s has %2$s!</string>
<string name="diseaseMessage2">%1$s has killed %2$s!</string>

String name = "Sally";
String disease = "Typhoid";

String strDisease1Format = getResources().getString(R.string.diseaseMessage);
String strDisease1Msg = String.format(strDisease1Format, name, disease);

String strDisease2Format = getResources().getString(R.string.diseaseMessage2);
String strDisease2Msg = String.format(strDisease2Format, disease, name);


INT => %1$d
STRING => %1$s

String Variable 1 => %1$s
Int Variable 2 => %2$d
Int Variable 3 => %3$d