I have a couple of Fragment
s with RecyclerView
s in a ViewPager
. On actions in the first Fragment
, the remaining Fragment
s change what they display.
I can access all the Fragment
s from the first one and call update methods on them. The problem is, the updates do not happen if I do not swipe to the other Fragment
s. In fact, before tapping any action buttons in the first Fragment
, I have to swipe to the other Fragment
s (without purpose) just to keep the app from crashing with a NullPointerException
.
The reason I guess is because the remaining Fragment
s are null
as they are not brought into view.
I have tried this approach so 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 to 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 to any fragments:
02-06 14:58:52.691 11967-11967/com.nearme E/AndroidRuntime: FATAL EXCEPTION: main Process: com.my, PID: 11967 java.lang.NullPointerException at com.my.s.Frag2.updatePager(Frag2.java:xxx)
So my question,
- Irrespective of the visibility of a
Fragment
in aViewPager
, how can they (Fragment
s) be kept ready with the latest content?