Skip to content
Sébastien Vitard edited this page Jan 16, 2019 · 6 revisions

Step 1: retrieve the default events list & display it

  1. Add the Volley library to the build.gradle file of the appfolder
  2. Complete the reset method of the MainActivity class using the Volley library (see documentation)
  3. Replace the root FrameLayout with a ListView in the activity_main.xml layout file
  4. In the meanwhile, create a row_main.xml layout file & complete it to fit the example below
  5. Create a MainAdapter class inheriting from ArrayAdapter & override its getView method
  6. Finally, complete the onCreate & reload methods of the MainActivity class

Step 2: start a new activity to create an event

  1. Create a menu_main.xml menu file & complete it in order to show a + item in the MainActivity. (Note: use ic_action_add drawable)
  2. Override the onCreateOptionsMenu & onOptionsItemSelected methods of the MainActivity to inflate the menu & launch the CreateActivity for result
  3. Declare the CreateActivity in the AndroidManifest.xml file
  4. Complete the fragment_detail.xml layout file to fit the example below
  5. Instead of typing in an EditText the date, set its editable attribute to false & show a DatePickerDialog when clicking on it & when it is focused. Then, set the date of EditText with the selected date
  6. Complete the onCheckOptionsItemSelected method of the CreateActivity class
  7. Finally, override the onActivityResult method of the MainActivity class to add the newly created event & reload the adapter

Step 3: reuse the code (that's the magic) to edit an event

  1. Update the onCreate method of the MainActivity class
  2. Override the onAttachFragment method of the EditActivity class
  3. Override the onCreate method of the DetailFragment class
  4. Update the onCreateView method
  5. Update the onActivityResult method of the MainActivity class

Step 4: last improvements with orientation & locale

  1. Create a values-fr folder in the res folder, copy it the strings.xmlfile & translate all values in FR ;)
  2. Create a layout-land folder in the res folder, copy it the activity_detail.xml file & update it to obtain a horizontal LinearLayout
  3. Override the onSaveInstanceState method of the DetailFragment class & update the onCreate one