This is my MainActivity.java.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String myString = "Mary";
int myInt = 12;
String formatted = getString(R.string.my_xml_string, myString, myInt);
}
}
string.xml
<resources>
<string name="app_name">My First App</string>
<string name="my_xml_string">My sister %1$s is %2$d years old.</string>
</resources>
However when I run the app,I still got ‘My sister %1$s is %2$d years old.’ as text. Anyone knows why?
On the side note, it says the variable formatted is not used. So how does that link to the string.xml file?
2
Answers
In case anyone is facing the same issue, I use
Try this
or