Coder Social home page Coder Social logo

morristech / updatablefragmentstatepageradapter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from inloop/updatablefragmentstatepageradapter

0.0 1.0 0.0 158 KB

FragmentStatePagerAdapter but with working notifyDataSetChanged() support

License: Apache License 2.0

Java 100.00%

updatablefragmentstatepageradapter's Introduction

UpdatableFragmentStatePagerAdapter

This is an improved version of the original FragmentStatePagerAdapter with important changes that add support for changing the order and count of items.

Two major problems exist in the FragmentStatePagerAdapter which make it impossible to use with notifyDataSetChanged(), these are desribed as part of our article [Adventures with FragmentStatePagerAdapter](Adventures with FragmentStatePagerAdapter):

You can build and look at the sample implementation.

How to use

The implemenation is the same as with the original FragmentStatePagerAdapter. You need to override two methods in order to support dataset changes:

@Override
public int getItemPosition(Object object) {
    YourFragment fragment = (YourFragment) object;
    // ... determine the position of the fragment in your dataset 
    // ... e.g. extract some ID from Arguments and search in your dataset
}

You need to return POSITION_NONE in case the dataset doesn't contain the item anymore. Always returning POSITION_NONE will work but will have an impact on performance (current Fragments are recreated even if the position hasn't changed).

Also you need to return a unique identifier for an item based on the position. This isually means returning an "ID" or hashcode of the item.

@Override
public long getItemId(int position) {
    // get the item in your dataset on this position and return some ID or hash code.
}

Download

compile 'eu.inloop:pageradapter:0.1.0'

updatablefragmentstatepageradapter's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.