A simple implementation of PagerAdapter that supports Views.
A ViewPagerAdapter for your ViewPager, this implementation will attempt to rebind to existing views when you call notifyDataSetChanged(), rather than recreate all the Views.
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>'
}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();
}
}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
