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?
ArrayAdapter.createFromResourcecalls a method, what creates an in-memory array (see line 391, or line 204 here)