title: Add new string to resource string array dynamically
body: <p>Im making workout log and i want that ther user will be able to add new exercise types.</p>
  
  <p>I made string array in the resources and a spinner that will take the strings from the string array in the resources.</p>
  
  <p>Im not sure how to add new string to resources string array from java code.
  I tried this code, but i get exception.</p>
  
  <p>thanks for helping :)</p>
  
  <pre><code>public void onClick(View v) {
  
      switch(v.getId()){
  
      case R.id.setNewExercise:
          String[] exerciseStringArray = getResources().getStringArray(R.array.exerciseTypes);
          ArrayAdapter&lt;CharSequence&gt; list = ArrayAdapter.createFromResource(this, R.array.exerciseTypes, android.R.layout.simple_list_item_1);
  
          String exerciseCheck = addNewExercise.getText().toString();
          try{
          for (int i = 0; i &lt; exerciseStringArray.length; i++)
          {
              if (exerciseCheck.equals(exerciseStringArray[i]))
              {
                  Toast.makeText(getApplicationContext(), "This exercise already exist", Toast.LENGTH_LONG).show();
                  break;
              }
              else if (i == exerciseStringArray.length - 1 &amp;&amp; exerciseCheck.equals(exerciseStringArray[i]) == false)
              {
                  list.add(exerciseCheck);
                  Toast.makeText(getApplicationContext(), "Added Successfully", Toast.LENGTH_LONG).show();
                  break;
              }
          }
          }catch(Exception e){
  
              Toast.makeText(getApplicationContext(), "wtf", Toast.LENGTH_LONG).show();
          }
  
      }
  
  }
  </code></pre>
  
  <p>Ive tried now this code, and my spinner is loaded empty and i get force closed when trying to save new string.</p>
  
  <pre><code>    /////////////////////Exercise spinner/////////////////////
      // Create an ArrayAdapter using the string array and a default spinner layout
      list = new ArrayList&lt;CharSequence&gt;();
      exerciseAdapter = new ArrayAdapter&lt;CharSequence&gt;(this, R.array.exerciseTypes, list);
  
      // Specify the layout to use when the list of choices appears
      exerciseAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
      // Apply the adapter to the spinner
      workOutChoose.setAdapter(exerciseAdapter);
  
  
  }
  
  @Override
  public void onClick(View v) {
  
      switch(v.getId()){
  
      case R.id.setNewExercise:
  
  
          String exerciseCheck = addNewExercise.getText().toString();
  
          try{
  
              if (exerciseAdapter.getPosition(exerciseCheck) &gt;= 0)
              {
                  Toast.makeText(getApplicationContext(), "This exercise already exist", Toast.LENGTH_LONG).show();
                  break;
              }
              else 
              {
                  exerciseAdapter.add(exerciseCheck);
                  exerciseAdapter.notifyDataSetChanged();
  
                  Toast.makeText(getApplicationContext(), "Added Successfully", Toast.LENGTH_LONG).show();
                  break;
              }
          }
          catch(Exception e){
  
              Toast.makeText(getApplicationContext(), "wtf", Toast.LENGTH_LONG).show();
          }
  
      }
  
  }
  </code></pre>