android - how to modifiy a list from ListFragment in its parent activity -
i have sherlocklistfragment , i'm creating adapter inside onactivitycreated. parent activity implements callback interface communicating fragments. when method activity called want add / remove item fragment's list. have tried use getlistadapter , receive npe. if use getlistview, "content view not yet created" error received. how can modify list fragment in correct way?
activity code:
@override public void addfavorite(contact item) { list<contact> favoritecontacts = ((favoritecontactsadapter) favouritecontactsfragment .getlistadapter()).getcontacts(); favoritecontacts.add(0, item); favoritecontactsadapter adapter = new favoritecontactsadapter( getapplicationcontext(), r.layout.contact_layout, favoritecontacts); favouritecontactsfragment.setlistadapter(adapter); }
fragment code:
@override public void onactivitycreated(bundle savedinstancestate) { contacts = getarguments() .getparcelablearraylist(constants.contacts_key); adapter = new favoritecontactsadapter(getactivity(), r.layout.contact_layout, contactsutils.getfavoritecontacts(contacts)); setlistadapter(adapter); ...
Comments
Post a Comment