Reputation: 850
I'm currently building an Android Agenda Activity which consists in 4 ListView. Basicaly, I got the method onAgendaDataReady(ArrayList appointments) that is called by a WebServiceCoordinator. This method sorts the appointments and that way, populates 4 new ArrayList. The code is the following :
@Override
public void onAgendaDataReady(ArrayList<Appointment> appointments) {
//swipeContainer.setRefreshing(false);
alert.hide();
ArrayList<Appointment> appointmentsfuturs = new ArrayList<>();
ArrayList<Appointment> appointmentspasses = new ArrayList<>();
ArrayList<Appointment> appointmentsannules = new ArrayList<>();
ArrayList<Appointment> appointmentsaconfimer = new ArrayList<>();
for (Appointment a : appointments) {
if (a.stateId == 2)
appointmentsaconfimer.add(a);
else if (a.stateId == 6)
appointmentsannules.add(a);
else if (a.stateId == 5)
appointmentspasses.add(a);
else if (a.stateId == 4)
appointmentsfuturs.add(a);
}
ArrayAdapter<Appointment> adapterfuturs = new ArrayAdapter<>(AgendaActivity.this, android.R.layout.simple_list_item_1, appointmentsfuturs);
ArrayAdapter<Appointment> adapterpasses = new ArrayAdapter<>(AgendaActivity.this, android.R.layout.simple_list_item_1, appointmentspasses);
ArrayAdapter<Appointment> adapterannules = new ArrayAdapter<>(AgendaActivity.this, android.R.layout.simple_list_item_1, appointmentsannules);
ArrayAdapter<Appointment> adapteraconfirmer = new ArrayAdapter<>(AgendaActivity.this, android.R.layout.simple_list_item_1, appointmentsaconfimer);
rdvFutursListView.setAdapter(adapterfuturs);
rdvPassesListView.setAdapter(adapterpasses);
rdvAnnulesListView.setAdapter(adapterannules);
rdvAConfirmerListView.setAdapter(adapteraconfirmer);
adapterfuturs.notifyDataSetChanged();
adapterpasses.notifyDataSetChanged();
adapterannules.notifyDataSetChanged();
adapteraconfirmer.notifyDataSetChanged();
}
This code is working, but I don't want anymore to use the android.R.layout.simple_list_item_1 layout. So I built an ArrayAdapter with a custom layout. My problem / question is the following : how to pass the ArrayList created by onAgendaDataReady() to my Adapter ?
I tried to do this :
appointmentItemAdapter = new AppointmentItemAdapter(this);
rdvFutursListView.setAdapter(appointmentItemAdapter);
appointmentItemAdapter.add(adapterfuturs);
But the appointmentItemAdapter requires an Appointment and not an ArrayList.
Thanks for your help
--------------- FINAL SOLUTION -----------------
AppointmentItemAdapter appointmentFutursItemAdapter = new AppointmentItemAdapter(AgendaActivity.this);
rdvFutursListView.setAdapter(appointmentFutursItemAdapter);
appointmentFutursItemAdapter.addAll(appointmentsfuturs);
appointmentFutursItemAdapter.notifyDataSetChanged();
Upvotes: 0
Views: 827
Reputation: 563
I think you are mixing different things here.
Your custom Adapter has to take an ArrayList (or any Collection) as input parameter and return the current items to the list (based on the position queried)
So it is not sufficient to pass a single Appointment as parameter.
Upvotes: 0