Android - String

Card Puncher Data Processing

About

String is a resource

Location

Located in /res/values/strings.xml

Formatting

Bad practice:

textView.setText(variable + " unitSymbol");

Good practice:

<!-- import the xliff namespace in the strings.xml -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Format it -->
<string name="welcome">
         Hi <xliff:g id="name">%1$s</xliff:g> 
         You have <xliff:g id="count">%2$d</xliff:g> new messages
</string>
  • Context.getString. From the context, you can get access to the string XML declaration.
String s = context.getString(R.string.welcome,myNameVariable, myCountVariable);

Localization

localization

Example

<resources>
    <string name="app_name">Sunshine</string>
    <string name="action_settings">Settings</string>
    <string name="refresh">Refresh</string>
</resources>

Documentation / Reference





Discover More
Card Puncher Data Processing
Android - (App) Resources (R)

The /res subdirectories contain the resources for your application: drawable-/: Directories for drawable resources, other than launcher icons, designed for various densities. layout: Directory...
Card Puncher Data Processing
Android - EmptyView

Message in the string.xml file to give a feedback In the onCreateView method See udacity/Advanced_Android_Development/blob/2.01_Empty_Database/app/src/main/java/com/example/android/sunshine/app/ForecastFragment.javaForecastFragment.java...
Card Puncher Data Processing
Android - Notification

Notification in Android In the string.xml, A notification message: A String that will be used as key in the preferences Strings related to Notification Enabled preference In pref_general.xml...
Android Account Sunshine
Android - Sync Manager Framework (SyncAdapter)

Introduced in Android Level 5. SyncAdapters are meant to keep local data on the device (a cache) in sync with data on the web with the goal of: fast load times, offline functionality and not...



Share this page:
Follow us:
Task Runner