I have the following string declared in strings.xml:
<string name="last_msg">Your last click was on</string>
Now when someone clicks a button, I want a textview to show this string, with a space, then a variable value that is a timestamp.
Unfortunately, using @string/last_msg isn't working, and I'm not sure how to do this properly so I'm not hardcoding in content.
Here's my code for the onClick function:
public void showMsgNow(View view) {
TextView lastMsg = (TextView)findViewById(R.id.textView2);
long currentTimeStamp = System.currentTimeMillis();
lastMsg.setText(@string/last_msg + " " + currentTimeStamp);
}
I'm a newbie, any help would be great !
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.
It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).
String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.
I found the answer on Google:
getString(R.string.last_msg)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With