0

I don't understand this anymore. I try to write a TextView

android:text="@string/dbVer"

define in strings.xml

<string name="dbVer">db %1$s</string>

and in Activity

int dbTag = Integer.parseInt(yearDay.format(new Date(new File(databasePath + "/ean_database.db").lastModified())));
String dbVer = String.format(getString(R.string.dbVer), dbTag );

The TextView is still showing: db %1$s

The nearest answer I found: Are parameters in strings.xml possible? is similar but in fact something is wrong for me.

1
  • After the code you posted in your Activity, do you call setText() on the TextView? Commented Jun 14, 2016 at 18:53

2 Answers 2

0

It looks like you are getting the result "db %1$s" because you are creating a string and assigning that as its value in the strings.xml file between these ><. What are you trying to have it show instead?

Sign up to request clarification or add additional context in comments.

Comments

0
android:text="@string/dbVer"

This refers to your format string and displays the raw format string you're seeing.

int dbTag = Integer.parseInt(yearDay.format(new Date(new File(databasePath + "/ean_database.db").lastModified())));
String dbVer = String.format(getString(R.string.dbVer), dbTag );

This creates a new string dbVer using the format string from resources.

What is missing is that you need to set this new string as your TextView's text:

TextView tv = (TextView)findViewById(R.id.your_textview_id); // assuming an activity
tv.setText(dbVer);

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.