Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access string.xml Resource File from Java Android Code

How do you access the values in the res/values/string.xml resource file from the Android Activity class?

like image 680
Ravikiran Avatar asked Aug 27 '11 10:08

Ravikiran


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.

Where is strings xml in Android?

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.

What is extract string resource in Android?

In Android Studio while adding TextView to the layout xml file, it is very convenient to use "Extract String Resource" to add string name to strings.


1 Answers

Well you can get String using,

getString(R.string.app_name); 

And, you can get string-array using

String arr[] = getResources().getStringArray(R.array.planet); for (int i = 0; i < arr.length; i++) {         Toast.makeText(getBaseContext(),arr[i], Toast.LENGTH_LONG).show();   } 
like image 177
Lalit Poptani Avatar answered Oct 10 '22 15:10

Lalit Poptani