I want to display a text in Alert Dialog from Strings/string.xml and depending on the results within the app, an additional text.
string.xml
dialog_title = "Hello world"
dialog_message = "I am the text from string.xml"
my alert dialog
alertBuilder
.setTitle(R.string.dialog_title)
.setMessage(R.string.dialog_message myClass.getText())
.setCancelable(false)
my getText() method
public class myClass {
public String getText() {
return "I am the text from the method" "\n" "I am a text from there, too"
}
}
Output:
Hello world
21283932323
I am the text from the method
I am a text from there, too
__
Whats wrong here? Why am I getting a number instead of the text from string.xml?
CodePudding user response:
you are referencing to id of string.dialog in that way
try:
myClass.getText().concat(R.string.dialog);
OR
getString(R.string.dialog).concat(myClass.getText());
I hope it help you: https://developer.android.com/guide/topics/resources/string-resource?hl=es-419#java