Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android set String value in String.xml

can anybody help me ?? I want to add String value through coding in string.xml
I am doing this.

  String name = getResources().getString(R.string.name);
  if(name.lenght() < 1 ){
      // getResources().setString(R.string.name);??????????????????????

  }

My string.xml is

 <?xml version="1.0" encoding="utf-8"?>
 <resources>
    <string name="name"></string>
 </resources>

does anybody know how i can add value of name in string.xml though coding. Thank you!!

like image 971
Mudassar Avatar asked Jun 09 '11 14:06

Mudassar


People also ask

How to add special characters in string XML in Android?

To include special characters inside XML files you must use the numeric character reference instead of that character. The numeric character reference must be UTF-8 because the supported encoding for XML files is defined in the prolog as encoding="UTF-8" and should not be changed.

How to add string in Android studio?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. In the above code, we have taken editext, button and textview. When user click on button after inserting value in edittext,it will append the data using string writer.


3 Answers

The resources are pretty much set in stone, so you can't modify them at runtime. If you need to store some new strings, use SharedPreferences or SQLite.

like image 63
Gabriel Negut Avatar answered Nov 10 '22 15:11

Gabriel Negut


I don't think you want to do that. If you are trying to store a value in a persistent way, take a look at SharedPrefences. Google has a good introduction to it here.

like image 6
Haphazard Avatar answered Nov 10 '22 15:11

Haphazard


It is not possible to modify the resources of an APK during runtime.

like image 5
Will Tate Avatar answered Nov 10 '22 15:11

Will Tate