Using strings from strings.xml in methods which expect strin

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Using strings from strings.xml in methods which expect strin

Postby kavik_bachani316 » Wed Aug 13, 2008 5:42 pm

i am trying to use the strings.xml file as much as possible for constant strings but there are places where eclipse is showing me errors.

Whenever i call a method, i want to send a string from the strings.xml file but using it generates an error which says it cannot use an int instead of a string.

example: showAlert("Delete Confirmation",...) works where as this doesn't. showAlert(R.strings.delete_confirmation,....)

Does anybody know of a possible workaround for this.

Thanks.
kavik_bachani316
Freshman
Freshman
 
Posts: 2
Joined: Wed Aug 13, 2008 5:35 pm

Top

Postby cgreen » Thu Aug 14, 2008 9:50 am

the R resources are integer values. probably an in-memory address of the strings constants. you'll have to read the string_located_at_(R.strings.delete_confirmation)
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Postby Jesmiatka » Thu Aug 14, 2008 1:55 pm

haven't coded Android in a while but it should be like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. this.getResources().getString(R.strings.delete_confirmation)
  3.  
  4.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Postby kavik_bachani316 » Thu Aug 14, 2008 2:39 pm

Thanks. It worked.
kavik_bachani316
Freshman
Freshman
 
Posts: 2
Joined: Wed Aug 13, 2008 5:35 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests