title: Android Array Adapter with ArrayList and ListView not updating when the arraylist is changed
body: <p>I have an android app with a screen that comprises of a ListView, which I am using to display a list of devices. These devices are held in an array. </p>
  
  <p>I am trying to use the ArrayAdapter to display what is in the array on the screen in a list. </p>
  
  <p>It works when I first load the <strong>SetupActivity</strong> class, however, there is the facility to add a new device in the <strong>addDevice()</strong> method, which means the array holding the devices is updated. </p>
  
  <p>I am using <strong>notifyDataSetChanged()</strong> which is supposed to update the list but it doesn't seem to work. </p>
  
  <pre><code>public class SetupActivity extends Activity
  {   
      private ArrayList&lt;Device&gt; deviceList;
  
      private ArrayAdapter&lt;Device&gt; arrayAdapter;
  
      private ListView listView;
  
      private DevicesAdapter devicesAdapter;
  
      private Context context;
  
      public void onCreate(Bundle savedInstanceState)  //Method run when the activity is created
      {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.setup);  //Set the layout
  
          context = getApplicationContext();  //Get the screen
  
          listView = (ListView)findViewById(R.id.listView);
  
          deviceList = new ArrayList&lt;Device&gt;();
  
          deviceList = populateDeviceList();  //Get all the devices into the list
  
          arrayAdapter = new ArrayAdapter&lt;Device&gt;(this, android.R.layout.simple_list_item_1, deviceList);
  
          listView.setAdapter(arrayAdapter);  
      }
  
      protected void addDevice()  //Add device Method (Simplified)
      {
          deviceList = createNewDeviceList();    //Add device to the list and returns an updated list
  
          arrayAdapter.notifyDataSetChanged();    //Update the list
  }
  }
  </code></pre>
  
  <p>Can anyone see where I am going wrong?</p>