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.

Community
  • 1
  • 1
Luc
  • 1
  • 1

2 Answers2

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?

Lyon12
  • 21
  • 5
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);
laalto
  • 150,114
  • 66
  • 286
  • 303