Read String and string array value from string.xml in android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings:
XML resource that provides a single string.
String Array
XML resource that provides an array of strings.
Quantity Strings (Plurals)
XML resource that carries different strings for pluralization.

All strings are capable of applying some styling markup and formatting arguments. For information about styling and formatting strings, see the section about Formatting and Styling.


<?xml version="1.0" encoding="utf-8"?>

getting string like this on activity:

String mess = getResources().getString(R.string.string_name);

String Array:

<string-array name="tabs_names"> 
<item>My Tab 1</item>
<item>My Tab 2</item>

getting string array like this on activity:

String[] tab_names = getResources().getStringArray(R.array.tab_names);

Happy Coding!!

No comments:

Post a Comment


Most recent Elastic Search tutorials for beginner, intermediate and advance level developer, Yubraj Pokharel, in CodingWorkspace