• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can code refer to the value of an R.string?

 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Being prodded by Android Studio, i've moved all my strings to resources in R.string. When displaying text in an object, this is seamless; Android knows to convert that int to a String. One of my methods returns an (int) error, and another method offers to translate that into a String. This latter method, i found out, must return an int, not a String, because the resource is an int. Nonetheless, on use, Android displays the String. All good. Weird, but good.

Now, another of my methods is to set a variable to some Strings, if there are any. (The Strings are provided outside my code.) If there are no Strings, a message is shown instead. That message is a literal, so i also put it in R.strings. Now, however, i have a problem. The variable is a String, but the resource is an int, so i cannot assign it to the variable.

How can code refer to the value of an R.string?
 
Maneesh Godbole
Saloon Keeper
Posts: 11312
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some short example code would help us understand the problem better.
 
Tim Moores
Bartender
Posts: 3127
50
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I fully understand the issue, but something like

getResources().getString(R.string.name_of_string)

should do the trick.
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:I'm not sure I fully understand the issue, but something like

getResources().getString(R.string.name_of_string)

should do the trick.


Yes, it does. Thank you!

I'm still learning the terms and was not sure how to ask the question, so i simply explained what i was thinking. Sorry for any confusion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic