Chapter 17 Two-Pane Master-Detail Interfaces
You also need to call updateCrime() in onActivityResult(...), where the Crime’s date, photo, and
suspect can be changed. Currently, the photo and suspect do not appear in the list item’s view, but
CrimeFragment should still be neighborly and report those updates.
Listing 17.16 Calling updateCrime() again (CrimeFragment.java)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
...
if (requestCode == REQUEST_DATE) {
Date date = (Date) data
.getSerializableExtra(DatePickerFragment.EXTRA_DATE);
mCrime.setDate(date);
updateCrime();
updateDate();
} else if (requestCode == REQUEST_CONTACT && data != null) {
...
try {
...
String suspect = c.getString(0);
mCrime.setSuspect(suspect);
updateCrime();
mSuspectButton.setText(suspect);
} finally {
c.close();
}
} else if (requestCode == REQUEST_PHOTO) {
...
getActivity().revokeUriPermission(uri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
updateCrime();
updatePhotoView();
}
}
Run CriminalIntent on a tablet and confirm that your RecyclerView updates when changes are made in
CrimeFragment. Then run it on a phone to confirm that the app works as before.
With that, you have an app that works on both tablets and phones.