Modify your cacheInBackground()
if (check_batch != batch_repeat) {
tempList.clear();
int lastOffset = getLastOffset();
if (lastOffset < LIST_SIZE) {
int limit = lastOffset + cutting_int;
for (int i = (lastOffset + 1); (i <= limit && i < LIST_SIZE); i++) {
tempList.add(list.get(i));
}
setLastOffset(limit);
if (limit <= 50) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
if (!firstTry) {// use this boolean to do it only once
tempList.clear();
int notDivisible = LIST_SIZE % cutting_int;
if (!(notDivisible == 0)) {
firstTry = true;
return true;
} else {
return false;
}
}
return false;
}
And replace your appendCachedData() method with this:
protected void appendCachedData() {
DownloadedOffersAdapter a = (DownloadedOffersAdapter) getWrappedAdapter();
if (check_batch != batch_repeat) {
if (getWrappedAdapter().getCount() <= 50) {
check_batch = check_batch + 1;
Log.v("Check", "append chk_batch " + check_batch);
for (int i = cutting_int; i < cutting_int + cutting_int; i++) {
a.add(list.get(i));
}
}
} else {// Append extra entries to list i.e less than cutting_int
int notDivisible = LIST_SIZE % cutting_int;
for (int i = (LIST_SIZE - notDivisible); i < LIST_SIZE - 1; i++) {
a.add(list.get(i));
}
return;
}
}