ViewPager not updating EditText or CheckBox values on swipe


Hi, all.

I have checked and rechecked my code, and I still cannot figure out why my CrimeFragment s are not being updated 100% by the ViewPager after swiping. The contents of the EditText box and the CheckBox are not being updated. The actionbar title is changing properly and the ViewPager is behaving properly otherwise. I mean it stops me from swiping right when I am viewing crime #0 (beginning of list of crimes).

If I click on a crime in the list, I do get a view with correct values for the EditText content and CheckBox state. This part works fine. If I hit the back button and click on a different crime in the list, same thing… it works perfect. The problem is when I swipe left or right. If I click on say, Crime #3, it shows me the correct Crime #3 fragment with correct values (Crime #3 for the actionbar title and Crime #3 shown in the EditText field, also the checkbox is unchecked like it should be for crime 3). When I swipe right (which should take me left to display the previous Crime #2) I see “Crime #2” in the actionbar title, but then the EditText shows “Crime #3” still. Also, the checkbox is still unchecked like it was in crime 3.

Does anyone know where my problem would be located in the code? I will happily supply the code for whichever classes/layout files that might be the culprit. Just tell me which ones please.



If anyone else has this problem, here’s the root of the bug:

// - onCreate()
public void onCreate(Bundle savedInstanceState) {
//UUID crimeId = (UUID)getActivity().getIntent()
// .getSerializableExtra(EXTRA_CRIME_ID);
UUID crimeId = (UUID)getArguments().getSerializable(EXTRA_CRIME_ID);
mCrime = CrimeLab.get(getActivity()).getCrime(crimeId);

The problem was due to the CrimeFragment not retrieving its arguments. For some reason I missed this section in the book (“Retrieving arguments” page 196). The part that’s commented out was what I had. I was missing the revised “(UUID)getArguments()…” line.

Took me a day and half to retrace my steps back to this page/section/code revision. Hopefully this will save time for others seeing the same behavior I described in the original post.


You’re the best, you saved my night. Got the same error, don’t know why I didn’t see it ! :smiley:

Thanks !


Thanks, I had the same problem and have been trying to figure this out all day on my own.


Thank you very much for this post. I had the exact same problem and spent a couple of hours looking for my error and then came here to look for clues. I also missed adding the line

UUID crimeId = (UUID)getArguments().getSerializable(EXTRA_CRIME_ID);

Thanks again!