Twing90
Twing90

Reputation: 417

add item to my stringarray

I have my category_array(String array) in my String.xml file. I use this string-array to populate a listview.

<string-array name="category_array">
    <item >Airplane</item>
    <item >Train</item>
    <item >Taxi</item>
    <item >Bus</item>
    <item >Food</item>
    <item >Drink</item>
    <item >Meeting Entrata</item>
</string-array>

Can I add an item getted from an editText from my Activity, to my category_array??

Upvotes: 2

Views: 242

Answers (5)

MAC
MAC

Reputation: 15847

You can not add data xml dynamically its used for static data which are not going to change in entire project.

Vector<String> vecString=new Vector<String>();

Then you can add strings dynamically...

vecString.add("Your Item1");
vecString.add("Your Item1");

Upvotes: 0

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

Nothing can be added in String.xml during runtime. For every item in string.xml.Android SDK provides a static integer during compile.i.e., in R.java file. So you can edit it during runtime if you need to any item during runtime i prefer you to use either ArrayList or Map

Upvotes: 0

waqaslam
waqaslam

Reputation: 68167

No, you cannot add items to a string-array dynamically. What you define in resources is always what you will get.

Resources are defined as public static final in R.

Upvotes: 0

Yugandhar Babu
Yugandhar Babu

Reputation: 10349

Its not possible, strings.xml file is read-only. you can't edit this file at run-time.

Upvotes: 2

pawelzieba
pawelzieba

Reputation: 16082

No, resources aren't editable. Use database instead.

Upvotes: 0

Related Questions