adapter.notifyDataSetChange() not working after called from onResume()


I am having a problem where when I call the adapter.notifyDataSetChange() to refresh the listActifity from the onResume() function, it doesn't seem to be working from any other functions from that activity afterwards.

I want the list(view) to refresh when the user clicks the back button(while on another screen) and returns to the window with the list. One of the things I noticed is that the notifyDataSetChange() works(from other functions) when I change one of the objects from the array list but not when I want to add or delete an object from the ArrayList. This has been working so far for me, but I would prefer not to have to requery the list every time.

@Override protected void onResume() { lightWeightDAO.open(); //db connection adapter.clear(); buckets = lightWeightDAO.getExerciseBucketsByWorkoutId(workout.getId()); adapter.addAll(buckets); adapter.notifyDataSetChanged(); super.onResume(); }

When I remove the notifyDataSetChange() from the onResume(), everything seems to work(just calling a simple notifyDataSetChange() after changing the arraylist).

Any idea why this is not working?


By using:

buckets = lightWeightDAO.getExerciseBucketsByWorkoutId(workout.getId()); adapter.addAll(buckets);

You have only <em>added</em> the contents of this new buckets to the adapter, you didn't <em>bind</em> the adapter to buckets. So this:

buckets.add(string); adapter.notifyDataSetChanged();

has no affect on the data inside the adapter. Also like I mentioned above in the comments, you can add to the adapter directly and it will call notifyDataSetChanged() for you. So simply replace everywhere you use the two lines above with:



  • How do I split on the space-separated math operators here?
  • VBA access: Refreshing a form from another form's code
  • Content Observer changes
  • Refresh/Requery Combobox problems
  • Variant from android-autofittextview library : scaling makes strange behaviour
  • Using multiple input pipelines in TensorFlow
  • Should I be afraid to use UDP to make a client/server broadcast talk?
  • How do I translate LR(1) Parse into a Abstract syntax tree?
  • in batch how do i use taskkill properly
  • Local Development, Apache vs Developer - file permissions
  • Application level floating views with navigation in Android
  • Git describe fails to return most recent annotated tag
  • AndEngine Applying Transparancy to AndEngine View
  • Using a canvas object in a thread to do simple animations - Java
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Debug.DrawLine not showing in the GameView
  • Alert pop up with LWUIT
  • Avoid links criss cross / overlap in d3.js using force layout
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • CSS Linear-gradient formatting issue accross different browsers
  • Regex thinks I'm nesting, but I'm not
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Fill an image in a square container while keeping aspect ratio
  • ILMerge & Keep Assembly Name
  • Large data - storage and query
  • Rearranging Cells in UITableView Bug & Saving Changes
  • WOWZA + RTMP + HTML5 Playback?
  • Calling of Constructors in a Java
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • AngularJs get employee from factory
  • Benchmarking RAM performance - UWP and C#
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Angular 2 constructor injection vs direct access
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Java static initializers and reflection
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Reading document lines to the user (python)
  • Python/Django TangoWithDjango Models and Databases