3

I'm using the default android NumberPicker and am having issues when using the setValue() method.

Just to note, the issues are occurring when i run API Level 16(Galaxy SII), I have tried an API Level 14 emulator and there are no issues so i'm a bit baffled.

My fragment contains number pickers and the numbers are saved to a DB table. I am returning the values to the number pickers when the fragment is accessed again.

Initially this works but if i replace the fragment in the activity, and then call the fragment again, the number pickers will display "0" but if i increase or decrease it, it will update from the number that it should be displaying. So 0 would jump to 5 if the number that is saved to the DB is 4.

Has anybody come across this and could they direct me on how to resolve this issue?

Thanks.

Paul
  • 31
  • 1
  • I am having this same issue (or at least, very similar). No database involved for me, but I swap out the fragment and then swap it back in, and the value remains what it was the last time the fragment was active. – Peter Gaultney Oct 15 '14 at 16:54

1 Answers1

0

I can't be certain without seeing your code, but my guess is that your Fragment has not overridden the onAttach() Fragment class method.

By overriding that method and performing my setValue() in that function like so, I was able to fix this issue:

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    if (number_picker != null)
        number_picker.setValue(desired_level);
}
Peter Gaultney
  • 3,269
  • 4
  • 16
  • 20