0

Iam working on an android app in which i get a response from a server in JSON format. I want to store the key value pair in strings.xml. How can it b done? The JSON response is as follows.

 {
"ResourceStrings": [
    {
        "Key": "AccountNumber",
        "Value": "Account Number"
    },
    {
        "Key": "AccountPassword",
        "Value": "Account Password"
    },
    {
        "Key": "AccountSettings",
        "Value": "Account"
    },
    {
        "Key": "AccountSettings.Load.InfoMessage",
        "Value": "The Account Number and Password only needs to be set one time.  \r\n\r\nIf you do not know the Account information please contact you system administrator or your DataXchange reseller."
    },
    {
        "Key": "Add",
        "Value": "Setup"
    },
    {
        "Key": "AddandModifytheScreens",
        "Value": "Add and Modify the Screens"
    },
    {
        "Key": "AddButton",
        "Value": "Add"
    },
    {
        "Key": "AddButtonClick.InfoMessage",
        "Value": "Enter the new information and press the Enter button to save the changes.\r\n\r\nOr, press the Cancel button to discard the new information."
    },
    {
        "Key": "AddCommunication",
        "Value": "Add Communication"
    },
    {
        "Key": "AdvancedSettings",
        "Value": "Advanced Settings"
    }
]
}
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
Fahad Abid Janjua
  • 1,024
  • 3
  • 14
  • 35
  • strings.xml is not meant for storing data generated during runtime. It is meant for storing any constants used for your layouts, etc. Consider using SharedPreferences, flat files or databases for storing those strings. – Vinay S Shenoy Oct 01 '12 at 12:14
  • User ArrayList/Array to store these vales and use it, Where you need. – Aerrow Oct 01 '12 at 12:16
  • @VinaySShenoy thanks for the suggestion now can you please show me how to save this response using shared preferences? – Fahad Abid Janjua Oct 01 '12 at 13:16

2 Answers2

7

You can't write anything in the strings.xml in runtime. Instead you can write to shared preferences, to database, or to file in the internal/external storage. All these ways are listed on Android Developers site.

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
0

as @ingsaurabh told

It is not possible to write anything in string.xml programmatically but can be done through SharedPreferences http://developer.android.com/guide/topics/data/data-storage.html#pref.

But have more values to so better to maintain database

Community
  • 1
  • 1
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78