0

I have a toolbar. And spinner that set on it. Now this spinner is strongly integrated in my code. So I prefer not change the structure mentioned down. Now the problem is that I have to store array in the resources. This is the problem because I want to programatically add/(delete) items that stored there. So the question is: If it is possible to prepare this array in activity?(and store ready array into resources) Or if is possible to add/delete specific item to array that locate into resources?

toolbar = (Toolbar) findViewById(R.id.toolbar);
SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.category, R.layout.spinner_dropdown_item);
            Spinner navigationSpinner = new Spinner(getSupportActionBar().getThemedContext());
            navigationSpinner.setAdapter(spinnerAdapter);
            toolbar.addView(navigationSpinner, 0);

This is how array looks like.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="category">
        <item>All lists</item>
        <item>Default</item>
        <item>Finished</item>
        <item>New List</item>
    </string-array>
</resources>

I found part of answer. But this allows only getting data from there, and not to store it after the treatment. How to add items to a stringArray in an arrayList programmatically?

5
  • You can modify the in-memory array. But you can't save it in your resources. Commented Jan 27, 2017 at 22:21
  • "modify the in-memory array" what do you mean? Commented Jan 27, 2017 at 22:22
  • You will read the array into an object, right? OK, you can copy that and add or remove items to THAT one. But you can't save the updates to a file in the resources folder. The resources folder is untouchable. Commented Jan 27, 2017 at 22:24
  • ArrayAdapter.createFromResource calls a method, what creates an in-memory array (see line 391, or line 204 here) Commented Jan 27, 2017 at 22:31
  • It means rewrite... Thanks Commented Jan 27, 2017 at 22:43

0

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.