Does calling an ArrayAdapter cause an infinite loop?

In my application, I have the option to save the item to my favorites. I save two identifiers in an ArrayList. When the user calls favorites, he goes through the arraylist and for each element, I get the corresponding data from my database. The information I return is again stored in the arraylist. I want to display this list in a Listview.

But the last step does not seem to work, as I am 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 is wrong.

Here I scroll through my first arralist with my identifiers:

public void getJobs(){
    for(int i = 0; i<vaca.size(); i++){
        getVacatures(vaca.get(i), kantoor.get(i));
        arrVacature.add(vacature);
    }
}

Here I call my data from the database:

 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+"&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);
}

, . .

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 && arrVacature.size() > 0){
            adapter.notifyDataSetChanged();
            for(int i= 0; i< 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();
        }
    }
};

( , getArray arrVacature.):

private class VacatureFavoAdapter extends ArrayAdapter<Vacature>{

    private ArrayList<Vacature> vacatures;


    public VacatureFavoAdapter(Context context, int textViewResourceId, ArrayList<Vacature> 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;
    }
}
+3
1

:

adapter.add(arrVacature.get(i));

ArrayAdapter add() , ArrayAdapter. , adapter VacatureFavoAdapter. , adapter.add() arrVacature.get(i) , ArrayAdapter. adapter?

, , adapter.notifyDataSetChanged().

+1

All Articles