2

I want to add certains strings as resource in file "strings.xml".

For example in this picture: enter image description here

I want to use ip1 and port1 as resources in "strings.xml" through java. Anyone know how to do ?

2 Answers 2

2

It is impossible to save or change values in strings.xml since it is a compiled resource. you can choose other ways to save datas, take a look at this:

https://developer.android.com/guide/topics/data/data-storage.html

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

Comments

1

strings.xml:

<resources>
    <string name="ip">INSERT TEXT FOR IP HERE</string>
    <string name="port">INSERT TEXT FOR PORT HERE</string>
</resources>

onCreate() within an Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Log.d("LOG_TAG", getString(R.string.ip));
    Log.d("LOG_TAG", getString(R.string.port));
}

Let me know if this answers your question.

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.