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");
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);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
favorietenWebService vs = new favorietenWebService();
xr.setContentHandler(vs);
xr.parse(new InputSource(url.openStream()));
vacature = vs.getVacatures();
} catch (Exception e) {
}
runOnUiThread(returnRes);
}
, . .
private Runnable returnRes = new Runnable(){
public void run(){
if (arrVacature.size() == 0){
dialog.dismiss();
}
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);
}
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;
}
}