If I understand your code correctly, there is something that your code does not correspond to the fragment life cycle or another fragment instance .
but. Life cycle problem
The Android framework expects your fragment to create its view inside the onCreateView() method. The view becomes available after the framework calls this method.
It is possible that your code named onLoadAndStoreComplete() before onCreateView() , and this caused the problem.
You need to extract a method to fill the actual views with data, since it can have 2 entry points. See code below:
public class MyFragment extends Fragment implements OnLoadAndStoreCompleteListener { private TableLayout tableLayout; private View rootView; private SomeDataClass loadedData; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContext = this.getActivity(); rootView = inflater.inflate(R.layout.fragment_permits, container, false); tableLayout = (TableLayout) rootView.findViewById(R.id.main_table); updateUi();
B. Miscellaneous Instance Failure
This can happen if you work in two different instances before the mentioned fragment.
At first, everything will look fine: onCreateView() , called before onLoadAndStoreComplete() . Therefore, check the following:
- The default logical / debug constructor for your fragment. You expect to receive one call for your fragment during the create / load stream.
- Check if the object named
onCreateView() the same object called onLoadAndStoreComplete() , you can use System.identityHashCode(this) , getting different values ββin these two methods is a bad sign
If this is what happens, the reason is probably hidden a little deeper, and without code I cannot give you exact advice on this. How do you create your fragment? Via XML or manually, then adding via FragmentManager or via ViewPager?
jskierbi
source share