Populate ListView with Dynamic Array
<p>I have a <code>EditText</code> box so a user can input names and then click the <em>Add</em> button and the name saves to the array <code>playerList</code> and clears the box so another name can be added.</p>

<p>I also have a <code>ListView</code> on the same Activity which will then be populated by the names in the <code>Array</code> <code>playerList</code>. The problem is that the <code>ListView</code> dosen't seem to be populated. </p>

<p>So I tried with a defualt set String <code>teststring</code> which you can see below and that populates the <code>ListView</code> fine. My question is how come it isn't working with the <code>Array</code> <code>playerList</code> maybe its not saving to the <code>Array</code> correctly?</p>

<p><strong>Update just need <code>adapter.notifyDataSetChanged();</code> adding to refresh the <code>ListView</code> Credit to @Lalit Poptani and @Jave</strong></p>

<pre><code>ArrayList&lt;String&gt; playerList = new ArrayList&lt;String&gt;();
ListView listview;
protected String[] teststring = {"Name 1", "Name 2"};

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.addremove);
ListAdapter adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, teststring);
ListView employeeList = (ListView) findViewById(R.id.namelistview);
employeeList.setAdapter(adapter);


Button confirm = (Button) findViewById(R.id.add);
confirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText playername = (EditText) findViewById(R.id.userinput);
String name = playername.getText().toString();
playerList.add(name);
playername.setText("");

}});
</code></pre>
