Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AppointmentsFragment extends Fragment {
- ArrayAdapter<Appointment> mAppointmentsArrayAdapter;
- List<Appointment> mAppointmentList = new ArrayList<>();
- ....
- ....
- private class GetAppointmentsAsyncTask extends AsyncTask<Void, Void, List<Appointment>> {
- @Override
- protected List<Appointment> doInBackground(Void... params) {
- APIService api = ApiAdapter.getInstance();
- List<Appointment> appointments = new ArrayList<Appointment>();
- try {
- List<Booking> bookingList = api.getBookings();
- for (Booking booking : bookingList) {
- appointments.add(new Appointment(booking));
- }
- } catch (RetrofitError r) {
- Log.d(TAG, r.getMessage());
- }
- return appointments;
- }
- protected void onPostExecute(List<Appointment> appointments) {
- mAppointmentsArrayAdapter.clear();
- mAppointmentsArrayAdapter.addAll(appointments);
- for(int i=0 ; i<mAppointmentsArrayAdapter.getCount() ; i++){
- Appointment obj = mAppointmentsArrayAdapter.getItem(i);
- Log.d(TAG, obj.toString());
- }
- mAppointmentListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Toast.makeText(getActivity().getApplicationContext(), "Clicked.",
- Toast.LENGTH_SHORT).show();
- }
- });
- mAppointmentsArrayAdapter.notifyDataSetChanged();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement