Giter Club home page Giter Club logo

view-pager-adapter's Introduction

๐Ÿ›‘ THIS REPOSITORY IS OFFICIALLY NO LONGER UNDER MAINTENANCE since 10/02/2022 ๐Ÿ›‘

view-pager-adapter Download

A simple implementation of PagerAdapter that supports Views.

Description

A ViewPagerAdapter for your ViewPager, this implementation will attempt to rebind to existing views when you call notifyDataSetChanged(), rather than recreate all the Views.

Adding to your project

To start using this library, add these lines to the build.gradle of your project:

repositories {
    jcenter()
}

dependencies {
    compile 'com.novoda:view-pager-adapter:<latest-version>'
}

Simple usage

ViewPagerAdapter is typed so you can specify the type of View explicitly. If you're making a ViewPager with just TextViews, you can use the following implementation:

class TextViewPagerAdapter extends ViewPagerAdapter<TextView> {
    
    private List<String> text;

    TextViewPagerAdapter(List<String> text) {
        this.text = text;
    }

    public void update(List<String> text) {
        this.text = text;
        notifyDataSetChanged();
    }

    @Override
    protected TextView createView(ViewGroup container, int position) {
        // inflate the view, do not attach to parent (the `false` param at the end of the `inflate()`)
        TextView view = (TextView) LayoutInflater.from(container.getContext()).inflate(R.layout.view_my_text_view, container, false);
        return view;
    }

    @Override
    protected void bindView(TextView view, int position) {
        String textForView = text.get(position);
        view.setText(textForView);
    }

    @Override
    public int getCount() {
        return text.size();
    }

}

Links

Here are a list of useful links:

  • We always welcome people to contribute new features or bug fixes, please see our contributing guide before opening a pull request
  • If you have a problem check the Issues Page first to see if we are working on it

view-pager-adapter's People

Contributors

ataulm avatar blundell avatar braisgabin avatar eduardb avatar electryc avatar juankysoriano avatar ouchadam avatar rock3r avatar tasomaniac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

view-pager-adapter's Issues

Why are AndroidX changes not released?

We're removing all android-support libraries from our project. view-pager-adapter is one of them. You have code changes migrating it to AndroidX but they are not included in any official release - why is that?

Offer a destroy view

Offer an opportunity to unbind from the view before destroying it. This should be to avoid users of the library having to override DestroyView and checking instance of.

This is where you would unbind listeners and clear bitmaps if needed.

The root views state is never restored

Currently the created View has an id manually set on it to ensure each view is unique, however we are not restoring the ids we give to the views.

Because we don't restore the id on the view when we attempt to restore the view hierarchy the views id is not found within the cached ViewState which means the views own state is not restored yet all its child views are as their ids have been maintained automatically.

ViewPagerAdapterState is using default classloader

There is a warning in ViewPagerAdapterState that the class loader is not being specified when we read the bundle.

private static ViewPagerAdapterState from(Parcel in) {
    Bundle bundle = in.readBundle();
    SparseArray<SparseArray<Parcelable>> viewStates = extractViewStatesFrom(bundle);
    return new ViewPagerAdapterState(viewStates);
}

On an internal project we have encountered crashes prior to setting the class loader explicitly, something like:

Bundle bundle = in.readBundle(ViewPagerAdapterState.class.getClassLoader());

It may be necessary to check the restoreState() method in ViewPagerAdapter:

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state instanceof ViewPagerAdapterState) {
        this.viewPagerAdapterState = ((ViewPagerAdapterState) state);
    } else {
        super.restoreState(state, loader);
    }
}

as this has a class loader as param.

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.