android - Keep 'distant' Fragments updated and ready for users in a ViewPager -
i have couple of fragment
s recyclerview
s in viewpager
. on actions in first fragment
, remaining fragment
s change display.
i can access fragment
s first 1 , call update methods on them. problem is, updates not happen if not swipe other fragment
s. in fact, before tapping action buttons in first fragment
, have swipe other fragment
s (without purpose) keep app crashing nullpointerexception
.
the reason guess because remaining fragment
s null
not brought view.
i have tried approach far, in vain:
public void updatepager(int pageposition) { ((nmmain) getactivity()).dsfragment.updatedsfragment(dview); nmparentviewpager = (viewpager) getactivity().findviewbyid(r.id.gssupremepager); nmparentviewpager.getadapter().notifydatasetchanged(); nmparentviewpager.setcurrentitem(pageposition, true); } // of updatepager()
log
after clicking action buttons in fragment1 after swiping fragments:
02-06 14:53:21.563 7765-8678/com.my a/nmdbhelper class: create view-1 query: create view view_temp 02-06 14:53:21.585 7765-8678/com.my a/nmdbhelper class: create dealsview-2 query: create table d_view 02-06 14:53:21.748 7765-7765/com.my e/dsfragment: in frag2.updatefragment(): dview.size() = 3
after clicking action buttons in fragment1 without swiping fragments:
02-06 14:58:52.691 11967-11967/com.nearme e/androidruntime: fatal exception: main process: com.my, pid: 11967 java.lang.nullpointerexception @ com.my.s.frag2.updatepager(frag2.java:xxx)
so question,
- irrespective of visibility of
fragment
inviewpager
, how can (fragment
s) kept ready latest content?
the way thinking , way worded question - oh complex.
all looking pre-load fragment pages. this post resolved it. so, viewpager.setoffscreenpagelimit()
answer.
though not my answer, hope bumps similar complexity , lands here.
thanks looking in, @cricket_007 , others.
Comments
Post a Comment