Question

I am trying to update my listfragment when a button is pressed. the button puts a name into a database but how do I update the list so that name appears? the listfragment uses a cursorLoader to load from the database. I even tried using a content observer on the database and calling getLoaderManager().restartLoader() but that didnt work either.

So what can I do to update the list when I click a button in an activity? I have found very little information on this please help

Was it helpful?

Solution

I can't be sure, but I assume there is something weird going on with the interaction between your Fragment and your Activity, which you are apparently displaying simultaneously somehow. Is there any reason why you are listening for the Button in the Activity? Are you dealing with a multi-pane screen or something? It seems like it'd be a lot simpler to just have the Fragment deal with this itself (since it is the one implementing the LoaderCallbacks, I assume).

Also, be sure that you are implementing your Fragment lifecycle correctly... i.e. you call initLoader() and set the list's adapter in onActivityCreated() as opposed to onCreate().

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top