Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1.  
  2. public class AppointmentsFragment extends Fragment {
  3.  
  4.     ArrayAdapter<Appointment> mAppointmentsArrayAdapter;
  5.  
  6.     List<Appointment> mAppointmentList = new ArrayList<>();
  7. ....
  8. ....
  9.     private class GetAppointmentsAsyncTask extends AsyncTask<Void, Void, List<Appointment>> {
  10.  
  11.         @Override
  12.         protected List<Appointment> doInBackground(Void... params) {
  13.             APIService api = ApiAdapter.getInstance();
  14.             List<Appointment> appointments = new ArrayList<Appointment>();
  15.             try {
  16.                 List<Booking>  bookingList  = api.getBookings();
  17.  
  18.                 for (Booking booking : bookingList) {
  19.                     appointments.add(new Appointment(booking));
  20.                 }
  21.             } catch (RetrofitError r) {
  22.                 Log.d(TAG, r.getMessage());
  23.             }
  24.             return appointments;
  25.         }
  26.  
  27.         protected void onPostExecute(List<Appointment> appointments) {
  28.             mAppointmentsArrayAdapter.clear();
  29.             mAppointmentsArrayAdapter.addAll(appointments);
  30.  
  31.             for(int i=0 ; i<mAppointmentsArrayAdapter.getCount() ; i++){
  32.                 Appointment obj = mAppointmentsArrayAdapter.getItem(i);
  33.                 Log.d(TAG, obj.toString());
  34.             }
  35.  
  36.             mAppointmentListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  37.                 @Override
  38.                 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  39.                     Toast.makeText(getActivity().getApplicationContext(), "Clicked.",
  40.                             Toast.LENGTH_SHORT).show();
  41.                 }
  42.             });
  43.             mAppointmentsArrayAdapter.notifyDataSetChanged();
  44.         }
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement