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"
    }
]
}
3
  • 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. Commented Oct 1, 2012 at 12:14
  • User ArrayList/Array to store these vales and use it, Where you need. Commented Oct 1, 2012 at 12:16
  • @VinaySShenoy thanks for the suggestion now can you please show me how to save this response using shared preferences? Commented Oct 1, 2012 at 13:16

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.