Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access a java variable in strings.xml

Tags:

java

android

How can I access a static java variable in a resource in strings.xml in the android studio?

I have a variable like this:

public static final String NUM_OF_DAYS = "10";

Now, I want to use this somehow in strings.xml in a resource.

EDIT:

I just want to use the string.xml resource (which will access NUM_OF_DAYS) in a java file.

like image 292
backslashN Avatar asked Mar 22 '26 07:03

backslashN


1 Answers

You can use your variable like this

public static final String NUM_OF_DAYS = "10";

string.xml

<string name="days">No of days: %s</string>

Java class

YOUR_VIEW.settext(getString(R.string.days, NUM_OF_DAYS));
like image 170
Pratik Popat Avatar answered Mar 24 '26 22:03

Pratik Popat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!