0

I have a listview which will update fine only when a button is pressed. When the button is pressed, the listener calls a method which applies a new arrayadapter and the changes are shown.

However if I call the method without the invoke of a button, nothing happens until the fragment's lifecycle refreshes.

1 Answers1

0

You shouldn't be applying a new array adapter every time the data changes. What you should be doing is making mods to the array the adapter is pointing to, with out changing where the adapter is pointing, and then calling notifyDataSetChanged(). see some other posts about this

https://stackoverflow.com/a/2708053/1116836

https://stackoverflow.com/a/2250849/1116836

http://androidadapternotifiydatasetchanged.blogspot.com/2013/02/android-notifydatasetchanged.html

that last one could be very helpful as a guide/tutorial on how it should be done.

Learning the best way to do this might take a bit of time, but once you figure it out it is a very easy and quick process doing it in other projects/areas from there on out.

Community
  • 1
  • 1
WIllJBD
  • 6,144
  • 3
  • 34
  • 44
  • Do you know why the method would work on a button invoke, but not on a context menu selection? I understand this is not the best way to approach the refresh, but why it is not working outside of a button invoke is baffling me. – user3516563 Apr 09 '14 at 18:43