1

EDIT: PROBLEM SOLVED. SEE COMMENTS BELOW...

I'm trying to implement an OnPageChangeListener to my ViewPager. I have issues determining the active fragment (name the class myFragment). Somewhere in my TabsAdapter the Fragment is set:

@Override
public Fragment getItem(int position) 
{
      TabInfo info = mTabs.get(position);
      return Fragment.instantiate(mContext, info.clss.getName(), info.args);
}

I think, that info.clss.getName() is like myFragment.class.getName(). If i call this:

FragmentManager fm = getSupportFragmentManager();

then myfragment.class.getName() appears in properties. But if i call this:

Fragment test = fm.findFragmentByTag(myfragment.class.getName());

test is null.

See what FM is at runtime:

fm  FragmentManagerImpl  (id=830007952696)  
    mActive ArrayList  (id=830007771376)    
        array   Object[12]  (id=830008021856)   
            [0] fragment1  (id=830007965416)    
            [1] myFragment (id=830008076232)    
            [2] null    
            ...
        size    2   
    mActivity   tabActivity  (id=830007948592)  
    mAdded  ArrayList  (id=830007781264)    
    mAvailBackStackIndices  null    
    mAvailIndices   null    
    mBackStack  null    
    mBackStackChangeListeners   null    
    mBackStackIndices   null    
    mCreatedMenus   null    
    mCurState   5   
    mDestroyed  false   
    mExecCommit FragmentManagerImpl$1  (id=830007953504)    
    mExecutingActions   false   
    mHavePendingDeferredStart   false   
    mNeedMenuInvalidate false   
    mNoTransactionsBecause  null    
    mPendingActions ArrayList  (id=830007908880)    
    mStateArray null    
    mStateBundle    null    
    mStateSaved false   
    mTmpActions Runnable[1]  (id=830007783384)

Another issue is, that the tab indicator isn't set to the active tab.

wog
  • 135
  • 3
  • 11
  • If I use Fragment.instatiate the Fragments WILL NEVER have an ID or a Tag! – wog Jul 20 '12 at 08:06
  • 1
    One way to get the ID or Tag of a fragment will be to call myFragment.getID when onCreateView() is called. I've tried to set a Tag, and writing update Methods... That worked. But was very sloopy because the update methods were ever called if an OnWheelChangedListener was called. I've got six wheels... Than I found this: http://stackoverflow.com/questions/9779397/detect-viewpager-tab-change-inside-fragment – wog Jul 21 '12 at 21:07

1 Answers1

0

(Answered in the comments. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

One way to get the ID or Tag of a fragment will be to call myFragment.getID when onCreateView() is called. I've tried to set a Tag, and writing update Methods... That worked. But was very sloppy because the update methods were never called if an OnWheelChangedListener was called. I've got six wheels... Then I found this: Detect ViewPager tab change inside Fragment

Community
  • 1
  • 1
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129