title: Android Spinner add items
body: <p>I'm working on an App and need some help with the spinner widget.
  The array has no entries by its creation and will be filled in another function. So I have to use <code>adapter.add(item);</code> and <code>spinner.setAdapter(adapter);</code> to update the spinner in this function, I guess.</p>
  
  <blockquote>
  <pre><code>// global variables
      String[] test = new String[100];
      int x = 0;
      Spinner s;
      ArrayAdapter adapter;
      Button btn1;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          btn1 = (Button) findViewById(R.id.button1);
          btn1.setOnClickListener(this);
          s = (Spinner) findViewById(R.id.spinner1);
          adapter = new ArrayAdapter(this,
          android.R.layout.simple_spinner_item, test);
      }
  
    public void onClick(View arg0) {
        test[x] = String.valueOf(x);;
        x++;
        adapter.add(test[x]);
        s.setAdapter(adapter);
    }
  </code></pre>
  </blockquote>
  
  <p>just for education purpose I tried this, but there is still a bug in the onClick() function.
  Something has to be done with the ArrayAdapter, I guess. But I don't familiar with this and didn't found an example for adding itmes by pressing a button.
  Maybe there is just a simple failure somewhere else, but currently I just don't see it.</p>
  
  <p>here the complete code:</p>
  
  <blockquote>
  <pre><code>    ArrayList&lt;Integer&gt;  test;
      int x = 0;
      Spinner s;
      ArrayAdapter adapter;
      Button btn1;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          btn1 = (Button) findViewById(R.id.button1);
          btn1.setOnClickListener(this);
          s = (Spinner) findViewById(R.id.spinner1);
          test = new ArrayList&lt;Integer&gt;();
          adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, test);
      }
  
    public void onClick(View arg0) {
        test.add(x);
        x++;
        s.setAdapter(adapter);
    }
  </code></pre>
  </blockquote>