Android : Simple way for a ListFragment to retain its associated adapter if it is auto reconstructed by the framework

on Friday, March 20, 2015


I want to be able to populate and repopulate an arrayadapter independantly from the listfragment to which it is set. I want to start populating the adapter independantly before it is set to the listfragment.


For this reason I want to pass the adapter to the listfragment. I cannot do this with the compulsory default constructor I don't really know an easy way to serialise (to use bundle) the adapter since in its items are quite complex. If I call setListAdapter if the listfragment is automatically recreated by the framework the adapter will be lost. I thought about holding the adapter in the associated activity and when onAttach is call retrieve it and call setListAdapter but it is the base activity that is passed. Maybe I could cast the activity, but there is a degree of presumption there and it all seems very messy.


Is there a "straight forward" way for the listfragment to get its original adapter if it is recreated by the framework?


0 comments:

Post a Comment