Skip to content

Instantly share code, notes, and snippets.

@sh-zam
Last active July 14, 2018 12:20
Show Gist options
  • Save sh-zam/40b3289cae60db884f44dfbdc0656873 to your computer and use it in GitHub Desktop.
Save sh-zam/40b3289cae60db884f44dfbdc0656873 to your computer and use it in GitHub Desktop.
Infinite gridView scrolling android with custom adapter
public class InfiniteScrollCustomAdapter extends ArrayAdapter<DataItems> {
// .... your code .....
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
int MAX_ITEM_PER_PAGE = 100;
// so data is retrieved before the page ends and user doesn't have to wait
if (position > (MAX_ITEM_PER_PAGE - 10)) {
// dataFetcher.next() should add to original list
dataFetcher.next();
}
if (convertView == null) {
convertView = getActivity().getLayoutInflater()
.inflate(R.layout.custom_layout, parent, false);
}
return convertView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment