How to create dynamic string

How to create dynamic string

Method for add some dynamic value to any string either value can string or integer. First of all, create a resource in your string.xml.

Lest take a example of version code of your application:

<string name="app_version">App Name (v%s)</string>

%s used for String, but you can use otrher identifiers like:

%s used for String.

%d used for Integer

 TextView app_version = (TextView) view.findViewById(R.id.app_version);
 app_version.setText(getString(R.string.app_version, BuildConfig.VERSION_NAME));

Output:

App Name (v2.0.1)

Write a comment
Loading...