From 786601482dd7bcfdfb3af4d957fa96c91e169b10 Mon Sep 17 00:00:00 2001 From: Sira Lam Date: Thu, 4 Jan 2018 17:48:00 +0800 Subject: [PATCH] Updated README for v1.1.0 --- README.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2cbd840..cf9bf06 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ A ViewPager and a PagerAdapter that can: 5. Won't scroll nor loop if there is only 1 item 6. Works well with notifyDataSetChanged() 7. Supports page indicators +8. Supports different view types ## Demo Effect @@ -50,7 +51,7 @@ allprojects { And then add the below to your app's build.gradle: ```groovy - implementation 'com.asksira.android:loopingviewpager:1.0.5' + implementation 'com.asksira.android:loopingviewpager:1.1.0' ``` ### Step 1: Create LoopingViewPager in XML @@ -98,7 +99,7 @@ public class DemoInfiniteAdapter extends LoopingPagerAdapter { //This method will be triggered if the item View has not been inflated before. @Override - protected View inflateView() { + protected View inflateView(int viewType, int listPosition) { return LayoutInflater.from(context).inflate(R.layout.item_pager, null); } @@ -107,7 +108,7 @@ public class DemoInfiniteAdapter extends LoopingPagerAdapter { //You can assume convertView will not be null here. //You may also consider using a ViewHolder pattern. @Override - protected void bindView(View convertView, int listPosition) { + protected void bindView(View convertView, int listPosition, int viewType) { convertView.findViewById(R.id.image).setBackgroundColor(context.getResources().getColor(getBackgroundColor(listPosition))); TextView description = convertView.findViewById(R.id.description); description.setText(String.valueOf(itemList.get(listPosition))); @@ -147,6 +148,21 @@ adapter.setItemList(newItemList); viewPager.reset(); //In order to reset the current page position ``` +## How do I implement different View types? + +Simple! Override one more method in your Adapter: + +```java + @Override + protected int getItemViewType(int listPosition) { + //Return your own view type, same as what you did when using RecyclerView + } +``` + +And then, of course, according to the `viewtype` parameter passed to you in `inflateView()` and `bindView()`, differentiate what you need to inflate or bind. + +You may also refer to the demo app for a complete example. + ## How do I integrate a Page Indicator? I don't provide a built-in page indicator because: @@ -240,6 +256,9 @@ if you cannot accept these minor defects, I suggest you use `onIndicatorPageChan ## Release notes +v1.1.0 +- Added support for view type. But therefore changed parameters needed in `inflateView()` and `bindView()`. + v1.0.5 - Added asepct ratio attribute for `LoopingViewPager` - Rewrote the way of caching Views in `LoopingPagerAdapter`, and therefore separated inflation and data binding