java - Update private ListFragment from parent activity -
i have fragmentactivity
creates listfragment
. inside listfragment
custom adapter. when try make adapter public, wouldn't let me. so, don't have access adapter or i'm not sure how it. add data listview
statically public arraylist of objects declare in lifecycle. however, other data want retrieve asynctask
database. data in parent activity , know right when finished fetching data. so, can update listview
within listfragment
access arraylist
, not access adapter? if so, can activity or need somehow call method in listfragment
? if need call method in listfragment
, how access method activity? if not possible without access adapter, how access adapter without public keyword? better move asyctask
listfragmen
t?
i know sounds lot, i'm wondering how refresh listview
cicumstances. appreciated.
call method:
listfragment fragment = (listfragment) getsupportfragmentmanager().findfragmentbytag("fragtag"); fragment.updatedata();
method refreshes:
public void updatedata(){ ((arrayadapter)this.getlistadapter()).notifydatasetchanged(); }
it in subclass of listfragment
, not in methods.
**edit:**now following error:
error parsing data java.lang.classcastexception: com.dynamic_internet_solutions.scsinfo.app.speakerlistfragment$1speakerslistadapter cannot cast android.widget.arrayadapter
**edit - solved: ** did
listfragment fragment = (listfragment) getsupportfragmentmanager().findfragmentbytag("fragtag"); baseadapter adapter = (baseadapter) fragment.getlistadapter(); adapter.notifydatasetchanged();
after set tag of fragment on initialization.
you have access listadapter of listfragment using getlistadapter() method. can grab list adapter , modify data in it. i'm not sure why having trouble making adapter public. declaring inline, or separate class? error getting compiler?
as aside, might want read 2 articles on view holder pattern , making reusable list adapters make listadapter more awesome.
Comments
Post a Comment