java - Calling Fragment Method from Activity in Swipeable Tab Views -



java - Calling Fragment Method from Activity in Swipeable Tab Views -

i've been working on project has swipeable views tabs.

the tabs exist fragments. want run fragment method main activity on periodic basis.

to run methos, dont' have id fragment. read in other posts that:

string tag = "android:switcher:" + tabactivity.this.viewpager.getid() + ":" + "0"; tab1fragment fragment = (tab1fragment) getsupportfragmentmanager().findfragmentbytag(tag); fragment.somemethod();

will homecoming fragment desire, happens zero-th or first tab. however, running code returns nullpointer exception.

any help appreciated. :)

in code, @ point must have:

fragmentmanager fm = getsupportfragmentmanager(); fragmenttransaction ft = fm.begintransaction(); ft.replace(r.id.framelayout, new somexyzfragment(), "some_xyz_fragment"); ft.commit();

add line:

fm.executependingtransactions();

after line ft.commit();

try this. should work.

java android android-fragments tabs swipe

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -