android - Calling ArrayAdapter causes infinite loop? -


in app, have option save item favourites. save 2 id's in arraylist. when user calls favourites, loops through arraylist , each item, corresponding data database. information again stored in arraylist. want display list in listview.

but last step doesn't seem work, i'm in infinite loop if call listviewadapter. don't quite understand why. stupid, can't find what's wrong.

here loop through first arralist id's:

public void getjobs(){     for(int = 0; i<vaca.size(); i++){         getvacatures(vaca.get(i), kantoor.get(i));         arrvacature.add(vacature);     } } 

here call data database:

 private void getvacatures(string vacaid, string kantoorid){         try {             log.e("in try", "try");             /* create url want load 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");             /* saxparser saxparserfactory. */             saxparserfactory spf = saxparserfactory.newinstance();             saxparser sp = spf.newsaxparser();              /* xmlreader of saxparser created. */             xmlreader xr = sp.getxmlreader();             /* create new contenthandler , apply xml-reader*/              favorietenwebservice vs = new favorietenwebservice();             xr.setcontenthandler(vs);              /* parse xml-data our url. */             xr.parse(new inputsource(url.openstream()));             /* parsing has finished. */              /* our examplehandler provides parsed data us. */             vacature = vs.getvacatures();          } catch (exception e) {         }         runonuithread(returnres); } 

here call adapter , dismiss dialog when list looped. goes wrong.

private runnable returnres = new runnable(){     public void run(){         if (arrvacature.size() == 0){             dialog.dismiss();         }          //for each time loop in debugger, adds items 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();         }     } }; 

this adapter class (note, getarray returns arrvacature array.):

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;     } } 

looking @ line:

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

an arrayadapter's add() method used add item whichever array has been assigned arrayadapter. assume adapter instance of vacaturefavoadapter. therefore, when call adapter.add() you're adding arrvacature.get(i) array backs arrayadapter. how have constructed adapter?

also, i'm not totally sure why you're calling adapter.notifydatasetchanged() twice.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -