Question about the R.string.variable resource

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

Question about the R.string.variable resource

Postby E-Nature » Mon Jan 04, 2010 9:33 pm

I am wondering if I can use placeholders in the string.xml file.
I have a text like this:

"Over 1000 cheats and counting!"


while the 1000 is from an integer variable. I want to use a placeholder in the string.xml file so I can replace this with the value of the int variable in the java code. is that possible?

The entry in the string.xml file would look like this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <string name="headline">Over %d cheats and counting!</string>
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Thanks for help in advance 8)
User avatar
E-Nature
Experienced Developer
Experienced Developer
 
Posts: 93
Joined: Mon Nov 16, 2009 3:39 pm

Top

Postby grzegorz.zajac » Mon Jan 04, 2010 9:47 pm

Hello,

Yes you can use placeholders (%d for integers, %s for strings, etc.)

Here is an example:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. int val = 1000;
  2.  
  3. String str = String.format(getString(R.string.headline), val);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


Regards,
Grzesiek
grzegorz.zajac
Developer
Developer
 
Posts: 39
Joined: Wed Feb 18, 2009 8:37 pm
Location: Krakow/Poland

Postby E-Nature » Tue Jan 05, 2010 8:27 am

thanks a bunch. works great :lol:
User avatar
E-Nature
Experienced Developer
Experienced Developer
 
Posts: 93
Joined: Mon Nov 16, 2009 3:39 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests