1
<item
    android:id="@+id/menu_selectDate"
    android:orderInCategory="100"
    android:showAsAction="ifRoom|withText"
    android:title="@string/date"/>   

I need this title to be variable to the selected date

1
  • What do you mean with "Let's say I have a variable string "date" in some other class, can I use this in my strings.xml file?"? A variable 'date' and the resource 'date' have nothing in common. Commented Jul 2, 2013 at 8:36

4 Answers 4

1

just try below code for get your string from your project resource:

String date= getApplicationContext().getResources().getString(R.string.date);
Sign up to request clarification or add additional context in comments.

1 Comment

I have my date set in another class, I want to use this in the strings.xml file to use it in my Android Menu.
0

Try this,

If it array of String then use,

String[] some_array = getResources().getStringArray(R.array.your_string_array);

Or else

String date= getApplicationContext().getResources().getString(R.string.date);

1 Comment

So I leave my string.xml empty? <string name="date"></string>
0

try this way

String res_date = Context.getResources().getString (R.string.date)

Please see the android developer guide this link

Comments

0

Leave the string name field empty in your layout. then in your activity write the following:

menu_selectDate.setText(YourDate);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.