79328017

Date: 2025-01-04 01:01:24
Score: 0.5
Natty:
Report link

I used MikeT's suggestion of iteration to solve this.

new popVacation() code:

public void popVacations(){
        repository = new Repository(getApplication());
        List<Vacation> allVacations = repository.getmAllVacations();
        ArrayAdapter<Vacation> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, allVacations);
        spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(spinnerAdapter);
        spinnerAdapter.notifyDataSetChanged();
        spinner.setSelection(findVacation(associatedVacation, allVacations));
    }

and the new findVacation:

public int findVacation(int associatedVacation, List<Vacation> allVacations) {
        int i = 0;
        for (Vacation vacation : allVacations){
            if (vacation.getVacationID() == associatedVacation){
                return i;
            }
            else i++;
        }
        return 0;
    }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Johnny Rinaldo