cwac-pager icon indicating copy to clipboard operation
cwac-pager copied to clipboard

Get Position by PageDescriptor

Open nicksardo opened this issue 11 years ago • 2 comments

Do you see any danger in providing the following? In my use case, I am constantly merging data to the PagerAdapter, and tracking the positions without entries would be painful.

public int getPosition(PageDescriptor pd){
    for(int x = 0; x < entries.size(); x++){
        if(getFragmentTag(x).equals(pd.getFragmentTag())){
            return x;
        }
    }
    return POSITION_NONE;
}

nicksardo avatar Sep 12 '14 10:09 nicksardo

I don't quite get the "tracking positions without entries" bit. That being said, I don't see any particular problems with that method. Tags need to be unique anyway, so the loop should be reliable.

commonsguy avatar Sep 12 '14 10:09 commonsguy

@commonsguy: Amazing work! It should replace the old FragmentStatePagerAdapter. @nicksardo : +1 useful suggestion. Accessing fragment position in entries whatever their state may be (detached/removed depending on the retention strategy - or - active) would be so useful. For instance, my model is a firebase, and when I receive a deletion information in the model, I cannot get the position in entries to actually remove it (in my TabLayout), if the corresponding fragments are not active. At least set getFragmentTag as protected.

Bamsoo avatar Jun 18 '15 22:06 Bamsoo