Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call getString(R.strings....) from class?

Is there a way to use the getString method from a seperate class?

I have a string stored in my strings xml, I'd like to use that string in an object... but the method isn't even available in the object...

any tips?

like image 963
Mars Avatar asked Sep 17 '11 11:09

Mars


People also ask

How do you get String from resources?

android:text="@string/hello" /> String string = getString (R. string. hello); You can use either getString(int) or getText(int) to retrieve a string.

Why should you use String resources instead of hard coded strings in your apps?

It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).

What is strings XML?

String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.

In which folder can you find the String resource file strings XML?

The XML resource files containing localized strings are placed in subfolders of the project's res folder.


1 Answers

resouce file: values/strings.xml

<resources>
   <string name="app_name">App name</string>
<resources>

java

import android.content.res.Resources;
Resources.getSystem().getString(R.string.app_name);//result : App name
like image 80
iCrazybest Avatar answered Oct 27 '22 10:10

iCrazybest