Note that there are some explanatory texts on larger screens.

plurals
  1. USJavaJoe
    primarykey
    data
    text
    plurals
    1. This table or related slice is empty.
    1. COWhat this boils down to is attempting to come up with a safe and robust solution to address the absence of a getFragment() method on the ViewPager. So as to not try to implement some hack to achieve this, it would appear the add() or replace() methods exist to assign a custom tag to my fragments for subsequent retrieval via findFragmentByTag(). The question is, when is it safe to perform these calls during the startup process? In other words, where/when call I call replace() and be sure the fragments have already been populated in the ViewPager so I can avoid this IllegalStateException?
      singulars
    2. COThanks for the link - I read through the suggestions and the proposed solutions have holes/dangers... 1)Maintaining my own collection of fragment references is prone to errors as this requires fully understanding ViewPager's behavior in order to ensure my collection is always in sync with ViewPager's fragment collection. 2)Calling findFragmentByTag() using ViewPager's internal fragment naming ("android:switcher:viewID:position") is dangerous as it relies on undocumented internal ViewPager implementation details.
      singulars
    3. COThanks for your reply. Agreed that simply returning new instances of my fragments in getItem() allows ViewPager to add them, however, I need a mechanism for being able to retrieve the fragment instance associated with a tab at some later time (usually when a tab becomes viewable or is going out of view) so that I can call a method on the fragment class to perform some desired behavior then. When I researched how to do that, the suggested method to retrieve fragments was to add a tag to them, and the only way to add a tag is via add() or replace() within a FragmentTransaction.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload