В моем приложении у меня есть возможность сохранить элемент в избранном.Я сохраняю два идентификатора в ArrayList.Когда пользователь вызывает избранное, он просматривает массив и для каждого элемента я получаю соответствующие данные из своей базы данных.Информация, которую я получаю, снова сохраняется в архиве.Я хочу отобразить этот список в ListView.
Но последний шаг, похоже, не работает, поскольку я нахожусь в бесконечном цикле, если я вызываю свой ListViewAdapter.Я не совсем понимаю, почему.Это будет что-то глупое, но я не могу найти, что не так.
Здесь я перебираю свой первый arralist с моими ID:
public void getJobs(){
for(int i = 0; i<vaca.size(); i++){
getVacatures(vaca.get(i), kantoor.get(i));
arrVacature.add(vacature);
}
}
Здесь я вызываю свои данные из базы данных:
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;
}
}