title: Calling ArrayAdapter causes infinite loop?
body: <p>In my app, I have an option to save an item to favourites. I save two ID's in an ArrayList. When a user calls favourites, it loops through the arraylist and for each item, I get the corresponding data from my database. The information I get back is again stored in an arraylist. I want to display this list in a Listview. </p>
  
  <p>But the last step doesn't seem to work, as I'm in an infinite loop if I call my ListViewAdapter. I don't quite understand why. It will be something stupid, but I can't find what's wrong.</p>
  
  <p>Here I loop through my first arralist with my ID's:</p>
  
  <pre><code>public void getJobs(){
      for(int i = 0; i&lt;vaca.size(); i++){
          getVacatures(vaca.get(i), kantoor.get(i));
          arrVacature.add(vacature);
      }
  }
  </code></pre>
  
  <p>Here I call my data from database:</p>
  
  <pre><code> private void getVacatures(String vacaid, String kantoorid){
          try {
              Log.e("in try", "try");
              /* Create a URL we want to load some xml-data from. */
  
              URL url = new URL("http://172.21.150.140:80/scripts/cgiip.exe/WService=brAccentBe/Android/getFavorieten.p?vacaid="+vacaid+"&amp;kantoorid=" + kantoorid);
  
              System.out.println("URL: "+ url);
              //URL url = new URL("http://dl.dropbox.com/u/22409181/offices.xml");
              /* Get a SAXParser from the SAXPArserFactory. */
              SAXParserFactory spf = SAXParserFactory.newInstance();
              SAXParser sp = spf.newSAXParser();
  
              /* Get the XMLReader of the SAXParser we created. */
              XMLReader xr = sp.getXMLReader();
              /* Create a new ContentHandler and apply it to the XML-Reader*/ 
              favorietenWebService vs = new favorietenWebService();
              xr.setContentHandler(vs);
  
              /* Parse the xml-data from our URL. */
              xr.parse(new InputSource(url.openStream()));
              /* Parsing has finished. */
  
              /* Our ExampleHandler now provides the parsed data to us. */
              vacature = vs.getVacatures();
  
          } catch (Exception e) {
          }
          runOnUiThread(returnRes);
  }
  </code></pre>
  
  <p>Here I do a call to my adapter and will dismiss the dialog when the list is looped. This is where it goes wrong. </p>
  
  <pre><code>private Runnable returnRes = new Runnable(){
      public void run(){
          if (arrVacature.size() == 0){
              dialog.dismiss();
          }
  
          //for each time I loop this in debugger, it adds items to my ArrayList...WHY?
          if(arrVacature!=null &amp;&amp; arrVacature.size() &gt; 0){
              adapter.notifyDataSetChanged();
              for(int i= 0; i&lt; arrVacature.size();i++){
                  adapter.add(arrVacature.get(i));
              }
              dialog.dismiss();
  
              TextView atlVacatures = (TextView)findViewById(R.id.atlVacatures);
              TextView atlVacaturesnr = (TextView)findViewById(R.id.atlVacaturesnummer);
              atlVacaturesnr.setText("" + arrVacature.size());
              atlVacatures.setText(" jobs op maat gevonden!");
  
              adapter.notifyDataSetChanged();
          }
      }
  };
  </code></pre>
  
  <p>This is my adapter class (Note, getArray just returns my arrVacature array.):</p>
  
  <pre><code>private class VacatureFavoAdapter extends ArrayAdapter&lt;Vacature&gt;{
  
      private ArrayList&lt;Vacature&gt; vacatures;
  
  
      public VacatureFavoAdapter(Context context, int textViewResourceId, ArrayList&lt;Vacature&gt; vacatures){
          super(context, textViewResourceId, vacatures);
          this.vacatures = getArray();
      }
  
      @Override
      public View getView(int position, View convertview, ViewGroup parent){
  
          View view = convertview;
          if(view==null){
              LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              view = vi.inflate(R.layout.vacature_list_item, null);
              //view.setBackgroundColor((position % 2) == 1? Color.LTGRAY: Color.WHITE);
          }
  
          Vacature vaca = vacatures.get(position);        
  
          if(vaca != null){               
              TextView tvNaam = (TextView) view.findViewById(R.id.vacatureNaam);
              TextView tvWerkveld = (TextView) view.findViewById(R.id.vacatureWerkveld);
              TextView tvRegio = (TextView) view.findViewById(R.id.vacatureRegio);
          if(tvNaam != null){   
  
              tvNaam.setText(vaca.getTitel());
              if(tvWerkveld != null){
                  tvWerkveld.setText("Werkveld: " + vaca.getWerkveld());
                  if(tvRegio!=null){
                      tvRegio.setText("Regio: "+vaca.getRegio());
                  }
              }
          }
          }
          return view;
      }
  }
  </code></pre>