java - Call getFragmentManager() without extending Fragment -
java - Call getFragmentManager() without extending Fragment -
i have class handling database in android app. when database changes, i'd update fragment displaying info frogment. approach has been give fragment tag , find fragment next code:
fragmentmanager manager = getfragmentmanager(); fragment fragment = manager.findfragmentbytag("schedule"); if (fragment instanceof schedulefragment){ schedulefragment fr = (schedulefragment)fragment; fr.scheduleupdated(); }
however, long database class not extension of fragment, compiler refuses recognise getfragmentmanager()
. me makes no sense extend fragment, database class no fragment, simple helper class manage database. possible reference fragment without extending fragment? or bad practice , should done in way?
also, possible reference fragment static method?
try using localbroadcast manager. when database changes laumch broadcast intent. registere in "schedule" fragment , can handle database changes. refer link more localbroadcast manager how utilize localbroadcastmanager? http://www.vogella.com/tutorials/androidbroadcastreceiver/article.html
java android android-fragments
Comments
Post a Comment