0

Really new to Java and Android but trying to learn. In process of creating a dialog alert I am using the stringbuilder to put together a message to the user. I am taking several lines of text from my string.xml file that looks like

<string name="lbl_deactivated_error">YOU HAVE BEEN DEACTIVATED</string>
<string name="lbl_notification_line2">Call Customer Service 1–800-xxx-xxxx-/string>
<string name="lbl_notification_line3">Email support@xxxx.com</string>
<string name="lbl_notification_line6">Please Exit By Pressing Home.</string>

My stringbuilder looks like

   AlertDialog.Builder dialog = new AlertDialog.Builder(ErrorActivity.this);
   dialog.setTitle(lbl_deactivated_error);
   alertmessage.append(lbl_notification_line2);
   alertmessage.append("\n");
   alertmessage.append(lbl_notification_line3);
   alertmessage.append("\n");
   alertmessage.append(lbl_notification_line6);
   dialog.setMessage(alertmessage.toString());
   dialog.show();

When executed, the alert shows with the title but the message shows a set of numbers, not the text as shown in the strings.xml. It prints each line of the text with the returns, but I get something like YOU HAVE BEEN DEACTIVATED

2131099688

2131099688

2131099688

Is there an obvious mistake I am making? Does it have something to do with the hyphens in the phone number maybe?

snowman
  • 123
  • 3
  • 10
  • Possible duplicate of [how to read value from string.xml in android?](https://stackoverflow.com/questions/2183962/how-to-read-value-from-string-xml-in-android) – Oleg Oct 05 '17 at 01:46
  • I can read the stirng.xml , I have import the R.string so just referencing the string name from the xml. The setTitle displays correctly. If I only do one line and just dialog.setmessage to one line it works. – snowman Oct 05 '17 at 01:58
  • That's because they can work with resource id, if you want to actually get the string you need to do what's described in the duplicate. – Oleg Oct 05 '17 at 02:00

1 Answers1

1

You need to get the String not the resource ID. Whenever you build it creates an R file that holds resource IDs (ints) for your resource pointers. You want to use the getString(R.string.lbl_notification_line3) instead.

Sam
  • 5,342
  • 1
  • 23
  • 39