cwac-pager
cwac-pager copied to clipboard
Get Position by PageDescriptor
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;
}
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: 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.