how to get string value in java in android

‮l.www‬autturi.com
how to get string value in java in android

To get a string value in an Android app in Java, you can use the getString() method of the Resources class. This method takes a resource ID as an argument and returns the string value associated with the ID.

Here's an example of how you can get a string value in an Android app in Java:

import android.content.res.Resources;

// ...

Resources resources = getResources();
String greeting = resources.getString(R.string.greeting);

In this example, the resources object represents the resources of the app, and the greeting variable holds the string value of the "greeting" resource.

To define a string resource in your app, you can add it to the strings.xml file in the res/values directory. For example:

<resources>
  <string name="greeting">Hello, World!</string>
</resources>

You can also use the getString() method to get a string value from a Bundle or Intent object.

Created Time:2017-11-01 20:42:55  Author:lautturi