0

If I have a button with an attribute of

    android:text="+1"

should it be included in the @string file or is it fine to be hardcoded in the activity_main?

KalebB
  • 11
  • 4

2 Answers2

1

Yes you can include them in the strings.xml(if being treated as strings , otherwise you should save them with <integer> tag). You don't need to explicitly put them in layout.

If being treated as strings (As in your case , you are setting it as string)

<string name="my_integer_value">3</string>

So it is accessible as android:text="@string/my_integer_value"

If being treated as Integers

<integer name="my_integer_value">3</integer> 
Aown Raza
  • 2,023
  • 13
  • 29
0

The answer depends on what the string is being used for. strings.xml is for UI strings that may be different in different configurations, most commonly different locales/languages. String constants that are meaningful to the app should generally not be in strings.xml.

Since this string is a button label, it should probably go in strings.xml.

Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82