Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Android | AlertBuilder Getting String text from values + method

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading