Reputation: 218
I have an array list and I want to do this logic
In the pager Adapter -
getCount() returns arrayList.size()
In the PagerAdapter - istantiateItem()
if(condition met)
add item to view
return view
else
return null
When I do that - whenever condition is not met , I see a blank item on the View Pager. How to not add a blank item to View Pager.
Upvotes: 1
Views: 182
Reputation: 16409
You need to override getCount()
method as well as getItem()
method with your condition check.
@Override
public int getCount() {
int size = 0;
for (Fragment fragment: fragmentList) {
if (fragment.isOK()) {
size++;
}
}
return size;
}
@Override
public Fragment getItem(int position){
int index = 0;
for (Fragment fragment: fragmentList) {
if (fragment.isOK()) {
if(index == position){
return fragment;
}
index++;
}
}
return null;
}
Upvotes: 1