user1687114
user1687114

Reputation:

Using a variable in strings.xml in Eclipse/Android

<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

Upvotes: 1

Views: 747

Answers (4)

taruna
taruna

Reputation: 61

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

menu_selectDate.setText(YourDate);

Upvotes: 0

Sunil Kumar
Sunil Kumar

Reputation: 7092

try this way

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

Please see the android developer guide this link

Upvotes: 0

No_Rulz
No_Rulz

Reputation: 2719

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);

Upvotes: 0

Stack Overflow User
Stack Overflow User

Reputation: 4082

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

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

Upvotes: 1

Related Questions