/** Update the list. */ private void updateUI() { CrimeLab crimeLab = CrimeLab.getInstance(getActivity()); List<Crime> crimes = crimeLab.getCrimes(); if (mAdapter == null) { mAdapter = new CrimeAdapter(crimes); mRecyclerViewCrime.setAdapter(mAdapter); } else { // mCrimes is gone. So the List<Crime> returned by getCrimes() // is a snapshot of the Crimes at one point in time. // we need to update the List<Crime> in the adapter in case user has edited a crime mAdapter.setCrimes(crimes); mAdapter.notifyDataSetChanged(); } // update subtitle after rotation updateSubtitle(); }
/** Updates the Interface with all the crimes in recycler views */ private void updateUI() { CrimeLab crimelab = CrimeLab.get(getActivity()); List<Crime> crimes = crimelab.getCrimes(); if (mAdapter == null) { mAdapter = new CrimeAdapter(crimes); mCrimeRecyclerView.setAdapter(mAdapter); } else { mAdapter.setCrimes(crimes); if (mPreviousAdapterSelected < 0) mAdapter.notifyDataSetChanged(); else { mAdapter.notifyItemChanged(mPreviousAdapterSelected); mPreviousAdapterSelected = -1; } } // make sure number of crimes stays up to date updateSubtitle(); }